// overloaded function
#include <iostream>
usingnamespace std;
int main ()
{
int x=1 , total=0;
while (x !=100)
{total =total + x;
x++;
}
cout << "the total is "<< total <<endl;
system ("PAUSE");
}
Not sure what you had in mind.... something like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main()
{
int last = 0;
for(int i = 0; i < 100; i++)
{
cout << i << " + " << last << "= " << i + last << endl;
last = i + last;
}
cout << "The final number is: " << last << endl;
return 0;
}
Or do you mean you want it to be 1 + 1 = 2, 2 + 2 = 4, and so on?
@rtom40
I think Kapo have explained it will , Also the Code2Code wrote another way to loop
If u wanna start From 1 So u will make X =1 and wanna to sum it to 10 for example u have to change the condition
It will be like that
1 2 3 4 5
int x= 1 , total=0;
while (x !=10){
total =total + x; // here are the statements which increase the total by x and increase x by 1 and it will happen until the condition is satisfied ( Until x becomes 10 ) //
x++;
}