Sunday, July 12, 2009

Display the sum of given 10 numbers without array in C++?

A program in C++ for 10 given numbers without arrays. This really stumped me...

Display the sum of given 10 numbers without array in C++?
accumulator?





take one variable and just keep adding the numbers to it? How are the 10 numbers given?
Reply:If it is strictly 10 numbers, no more, no less, I would suggest using a loop that repeats asking for a number 10 times, and inside of it keep a running total with total = total +number. Remember to use a loop control variable and set it to 0 and increment it every time it runs through.
Reply:get a variable " x " ( i meant total no;)


add to another variable(sum)


get it and add it till "x" comes





i think that's it :::::


i am illiterate (on c++)
Reply:keep a running a total of the numbers as they are entered by the user.





pcode:


userInput;


total = 0;


for(int x =1; x %26lt;= 10; x++)


{


cin %26lt;%26lt; userInput;


Total = Total + userInput;


}


No comments:

Post a Comment