Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6593007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:37:38+00:00 2026-05-25T17:37:38+00:00

I need to create a simple c# application to add some quarterly figures. I

  • 0

I need to create a simple c# application to add some quarterly figures. I am using arrays to “store” the data and then place it in a textbox.

Anyways, I am having some issues with my calculate section. I have put comment tags around it so you guys can easily find it. The area works, but it requires two clicks and adds it to the line above. I have been looking at the same few lines for about an hour and can not seem to figure this one out. Any ideas out there?

    //Global
    int lastIndexUsed = -1;
    int[,] quarters = new int[10, 5];
    string[] Branch = new string[10];

    public FrmSales()
    {
        InitializeComponent();
    }

    private void txtBranch_TextChanged(object sender, EventArgs e)
    {

    }

    private void btnCalc_Click(object sender, EventArgs e)
    {
        int Q1;
        int Q2;
        int Q3;
        int Q4;


        Q1 = int.Parse(txtQ1.Text);
        Q2 = int.Parse(txtQ2.Text);
        Q3 = int.Parse(txtQ3.Text);
        Q4 = int.Parse(txtQ4.Text);

        lastIndexUsed = lastIndexUsed + 1;
        quarters[lastIndexUsed, 0] = Q1;
        quarters[lastIndexUsed, 1] = Q2;
        quarters[lastIndexUsed, 2] = Q3;
        quarters[lastIndexUsed, 3] = Q4;
        Branch[lastIndexUsed] = txtBranch.Text;








        //Display Results

        int ctr;
        int ctr2;
        string outLine;
        string tempName;

        int row;
        int col;
        int accum;


        txtInfo.Text = "";

        outLine =           "  Branch       Q1         Q2         Q3         Q4       Total   " + "\r\n";
        outLine = outLine + "========== ========== ========== ========== ========== ==========" + "\r\n";

        txtInfo.Text = outLine;


        for (ctr = 0; ctr <= lastIndexUsed; ctr++)
        {

            outLine = "";

            tempName = Branch[ctr].PadLeft(10);
            outLine = outLine + tempName + " ";

            for (ctr2 = 0; ctr2 <= 4; ctr2 = ctr2 + 1)

            {


                outLine = outLine + quarters[ctr, ctr2].ToString().PadLeft(10) + " ";

            }

            txtInfo.Text = txtInfo.Text + outLine + "\r\n";


        }

        //Calculate ###########################################################

        for (row = 0; row <= lastIndexUsed; row++)
        {

            accum = 0;


            for (col = 0; col <= 3; col++ )
            {

                accum = accum + quarters[row, col];

            }
            quarters[row, 4] = accum;
        }




        //End Calculate #########################################################

    }

    private void btnClear_Click(object sender, EventArgs e)
    {
        txtBranch.Text = "";
        txtQ1.Text = "";
        txtQ2.Text = "";
        txtQ3.Text = "";
        txtQ4.Text = "";
        txtInfo.Text = "";

    }

    private void btnExit_Click(object sender, EventArgs e)
    {
        Close();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:37:39+00:00Added an answer on May 25, 2026 at 5:37 pm

    The problem is simple: you use the quarters array before you actually calculate the values for it. Move the “calculate” loop to be above the first loop.

    Also (among other things):

    • Too many blank lines and whitespace; makes it hard to read
    • Don’t try to make a formatted report using text; just use a DataGridView or similar
    • If you click the button enough times, you will have an array index out of bounds exception, because lastIndexUsed will go above 10.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a simple editor using a RichTextBox control in a windows
I'm doing some test on a very, very simple application using Spring . My
I need to create simple reusable javascript object publishing several methods and parameterized constructor.
i have very simple problem. I need to create model, that represent element of
I need a very simple and clear example of how to create an OCX
I need to add TWAIN scanning to an Delphi application and am having trouble
I have some pages designed by someone else as simple HTML that I need
I wrote some code to connect the application to it's database, then I created
we got high-load java application which works in clustered mode. I need to add
I have simple console application project for live video streaming using cross-platform libs on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.