Ask Question
21 December, 19:45

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.

+2
Answers (1)
  1. 21 December, 20:13
    0
    Following are the statement in C+ + Language is given below

    total=0; / / variable declaration

    cin >> amount; / / Read the input

    while (amount >=0) / /iterating the loop

    {

    if (amount>0) / / checking condition

    total=total+amount; / / perform operation

    }

    Explanation:

    Following is the description of the statement

    Declared a variable "total" and initialized with them 0 to them. Read the input in the "amount" variable by using cin. iterating the loop when the amount is greater then 0. Checking the condition if (amount>0) then adding the total variable and amount and storing them into the total variable.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers