#include <iostream>
usingnamespace std;
int main()
{
int number;
int sum = 0;
cout << "Enter the first number:";
cin >> number;
sum = 0;
for (int counter = 1; counter <= number; counter++)
{
cout << sum + number << endl;
}
cout << sum << endl;
return 0;
}
Read input in the loop to get the new values and add them to 'sum' ( ie: sum += input_you_get; // make 'sum' increasing )
Notice that you will need to get input in a new variable ( not 'number' ) or your loop will go crazy
#include <iostream>
usingnamespace std;
int main()
{
int number;
int sum = 0;
int input = 0;
cout << "Enter the first number:";
cin >> number;
sum += input;
for (int counter = 1; counter <= number; counter++)
{
cout << sum + number << endl;
}
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int number;
int sum = 0;
int input = 0;
cout << "Enter the first number:";
cin >> number;
for (int counter = 1; counter <= number; counter++)
{
sum += input;
cin >> number;
cout << sum + number << endl;
}
return 0;
}