# Could someone help me with this for loop I wrote?

• 09-30-2011
English_Fire
Could someone help me with this for loop I wrote?
I've just started C++ this week, and I have an assignment where you have to create a console application that asked the user how many numbers they would like to sum together, and then loops that many times, taking in a number and adding it to the sum each time. This is what I have -

Code:

```int main() {         int repeat_amount, sum = 0, entered_number;         cout << "Enter the amount of numbers you wish to add together: ";         cin >> repeat_amount;         for (int number = 0;number == repeat_amount; number ++) {                 cout << "Enter a number: ";                 cin >> entered_number;                 sum = sum + entered_number;         }         cout << sum; }```
The result is it doesn't allow me to enter any numbers except the first one. This is what I get when I run it -

Enter the amount of numbers you wish to add:
(then i enter a number and hit enter)
0Press any key to continue...
• 09-30-2011
manasij7479
Write
for (int number = 0;number < repeat_amount; number ++)
• 09-30-2011
English_Fire
I'll try that in a second, let me close out of this other program I started. Thanks for the response.

Edit: Okay, that fixed it. That was such a small error and I had to ask for help, haha. But thanks man, I appreciate it very much.
• 09-30-2011
meterpreter
Can U explain why number == repeat_amount' statement is not correct?
• 09-30-2011
manasij7479
Quote:

Originally Posted by meterpreter
Can U explain why number == repeat_amount' statement is not correct?

Because, that does not evaluate to be true for the required no. of times.
• 09-30-2011
Elkvis
a for() loop repeats while the second parameter is true. if you initialize number to zero, it will not be equal to repeat_amount on the first iteration of the for loop, so it won't even run once.
• 09-30-2011
meterpreter