Calculating and outputting numbers

Hi, I just have a query. How would I go about adding numbers together to output the total along with the program showing 1 - 100.

Not a very good explanation, I know. It's hard to find the right words to say so here is the code, basically I just need to add every number that is shown together and output the total at the end!

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

int main()
{
	for(int count=0; count< 101; count++)
     {
             cout <<count<<endl;
             }
             
system("Pause");
}


Thanks.
Last edited on
So, you're adding all numbers from 1-100?
After outputting them yeah :)
You need to track the current value and add them as you go:

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

int main()
{
    int sum = 0; // This will track your running total.
    for(int count=0; count< 101; count++)
    {
        cout <<count<<endl;
        sum += count; // Add the current number to the sum
    }
    cout << sum << endl; // output the sum
             
    system("Pause");
}
Topic archived. No new replies allowed.