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!
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>
usingnamespace 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");
}