I am new to the C # basic course and itβs hard for me to get a job. I built a basic calculator and it works great. Now I had to add a new button called "Amount", which will take input from one of my fields (number1Txtbox) and add it to myself 10 times through the loop.
I poured the pages of my C # book and cannot understand what it is. I figured out how to initialize a loop with a counter, etc., I just can't get this to work for life.
I was told to use a for loop, and then switch to a while loop. This makes no sense to me; I suggested that I could do this with a for loop. So my question is:
1) Do I even need to switch to a while loop to do this?
2) What am I doing wrong?
Here is what I have so far, and it just makes my program freeze when I try to press the sum button after putting the number in the text box:
private void sumBtn_Click(object sender, EventArgs e) { int counter; int loopAnswer; int number1; number1 = int.Parse(number1Txtbox.Text); for (counter = 1; counter <= 10; counter++) { loopAnswer = number1 + number1; do { loopAnswer = loopAnswer + number1; } while (counter <= 10); equalsBox.Text = loopAnswer.ToString(); } }
Thanks guys!
source share