Can anyone tell me why with using the for loop I have, it repeats the
the cout statement 5 times instead of what I had intended it to do, which was repeat the block of code 5 times.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main()
{
int A;
int FirstNumber;
int i = 0;
for (; i < 5; i++)
cout << "enter a number to add to 20 such as 20 + __ = A" << endl;
cin >> FirstNumber;
A = (FirstNumber) + 20; // Must put int variables in a separate parantheses
cout << "20 +" << FirstNumber << " = " << A << endl;
cout << "A = " << A << endl;
cout << "enter a number to add to 20 such as 20 + __ = A" << endl;
modfied codes:
#include <iostream>
using namespace std;
int main()
{
int A;
int FirstNumber;
int i = 0;
for (; i < 5; i++)
{
cout << "enter a number to add to 20 such as 20 + __ = A" << endl;
cin >> FirstNumber;
A = (FirstNumber) + 20; // Must put int variables in a separate parantheses
cout << "20 +" << FirstNumber << " = " << A << endl;
cout << "A = " << A << endl;
}
}