Hello,
I am supposed to write a statement for a Codelab review test that asks:
"Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0."
I entered in:
total=0;
for (amount=1; amount>0; amount++){
cin >> amount;
total += amount;
}
When I submit my response, I am told that I am not correctly calculating the correct value.
As far as I see it, the loop continues until a negative number is entered, so cin keeps getting values, and total is accumulating the values. Is my logic wrong?
Thanks for your help, I do not have a full script because we just enter snippets.