- #1
liquidicy
- 3
- 0
Very simple C program ( running total) [solved]
Question is:
Given that two int variables, total and amount , have been declared, write a sequence of statements that:
initializes total to 0
reads three values into amount , one at a time.
After each value is read into amount , it is added to the value in total (that is, total is incremented by the value in amount ).
My answer is this:
total = 0;
amount = 0;
do{
++amount;
total += amount;
}while (amount < 3);
Their response is:
Remarks:
⇒ Did you read in all three values?
Remarks:
⇒ At Execution
What did I do wrong?
Homework Statement
Question is:
Given that two int variables, total and amount , have been declared, write a sequence of statements that:
initializes total to 0
reads three values into amount , one at a time.
After each value is read into amount , it is added to the value in total (that is, total is incremented by the value in amount ).
Homework Equations
The Attempt at a Solution
My answer is this:
total = 0;
amount = 0;
do{
++amount;
total += amount;
}while (amount < 3);
Their response is:
Remarks:
⇒ Did you read in all three values?
Remarks:
⇒ At Execution
What did I do wrong?
Last edited: