jeudi 26 mars 2015

how can we add first 10 integers using while loop in c++



#include <iostream>
using namespace std;
int main()
{
int howmany;
int i=0;
cout <<"How many integers you want to add,just enter the number.\n";
cin >> howmany;

while (i < howmany)
{
int sum = 0;
sum = sum +i;
i++;

cout << sum << endl;
}
system ("pause");
return 0;

}


what is the mistake? It gives me list of numbers rather than their sum.I have tried to change order of statements in loop body but still problem not solved.




Aucun commentaire:

Enregistrer un commentaire