232k views
3 votes
Given that two int variables, total and amount, have been declared, write a loop that reads integers into the amount and adds all the non-negative values into the total. The loop terminates when a value of less than 0 is read into the amount. Don't forget to initialize total to 0.

1 Answer

3 votes

Answer:

total=0;

do{

cin >> amount;

if (amount>0)

total += amount;

}

while (amount >=0);

Step-by-step explanation:

User Eugene Gavrilov
by
4.4k points