### Algorithm

How to write an Algorithm for this? Design a loop that asks the user to enter a number. The loop should iterate 10 times and keep a running total of the numbers entered.

That's not an algorithm. That's simple addition. This appears to be more of a task on how much language syntax you understand than the actual "algorithm".
Last edited on
Yes, but I was asked to write an algorithm for it
Have you tried to write the code ? Sorry I don't mean to be an asshole rude, but at least post your code first so we know that you have tried to do it and not just asked for helping in doing a homework, The rule in this forum is we all discuss about a problem, solve it together and help the others in learning process, not give them the answer of their homework..
`total+=enteredNumber;`
Sorry I forgot to post what I was working on. Here is my algorithm.

declare integer product =0
declare integer inputValue
declare integer countNumber =10
do while countNumber>0
cout<< Please enter a whole number
cin>> inputValue
product = product + inputValue
countNumber = countNumber - 1
display The product of the ten numbers you entered is: " product

You dont really need to use a variable in a do..while loop, a simple for..loop would do the trick. I agree with LuminaChen and you shouldnt really expect others to do your homework, but sometimes an example will help with the learning and help you progress.

Don't just copy it and use it, you need to fully understand what's happening in the code otherwise you won't be any further forward when your next homework comes... experiment, experiment and experiment... :)

 ``1234567891011121314151617181920`` `````` #include using namespace std; int main() { int total = 0; int enteredVal; for (int i = 1; i <= 10; i++) { cout << "Enter a whole number ("<> enteredVal; total += enteredVal; } cout << "Total of all 10 numbers was: " << total; return 0; } ``````

Last edited on
thanks so much for your input, but I finally worked it out.
Brilliant :)
Topic archived. No new replies allowed.