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".
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..
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... :)
#include <iostream>
usingnamespace std;
int main()
{
int total = 0;
int enteredVal;
for (int i = 1; i <= 10; i++)
{
cout << "Enter a whole number ("<<i<<"): ";
cin >> enteredVal;
total += enteredVal;
}
cout << "Total of all 10 numbers was: " << total;
return 0;
}