help on looping

i need a program that will do this
if 4 is inputted the sum is 10 but it will display this 1+2+3+4 before it shows the sum can anyone help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  # include <iostream>
using namespace std;

int main()
{
    int sum = 1;
    int num;
	for(int i=1;i<num;i++)
	
		cin>>num;
	{
		cout << sum << " ";
        sum += i;
    }
    
    return 0;
}
Last edited on
# include <iostream>
using namespace std;

int main()
{
int sum = 0;
int count = 1;
int num;
cin>>num;
for(int i=1;i<=num;i++)
{

sum += i;
cout << i <<" + ";
}
cout<<endl;
cout<<sum <<endl;

return 0;
}

havent tried it though..but i think it works
i tried your program but it has 4 errors and 3 warnings
are you kidding me.its working.what kind of errors can you possibly get with that small chunck of code
just tried it again sorry for the confusion dude!
thanks for the help
:D
Topic archived. No new replies allowed.