Note that there are some explanatory texts on larger screens.

plurals
  1. POHow come my "calculate" will not work?
    primarykey
    data
    text
    <p>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. </p> <p>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? </p> <pre><code> //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 &lt;= lastIndexUsed; ctr++) { outLine = ""; tempName = Branch[ctr].PadLeft(10); outLine = outLine + tempName + " "; for (ctr2 = 0; ctr2 &lt;= 4; ctr2 = ctr2 + 1) { outLine = outLine + quarters[ctr, ctr2].ToString().PadLeft(10) + " "; } txtInfo.Text = txtInfo.Text + outLine + "\r\n"; } //Calculate ########################################################### for (row = 0; row &lt;= lastIndexUsed; row++) { accum = 0; for (col = 0; col &lt;= 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(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload