Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

loop that asks the user for an integer ten times Have the loop total the integers given, also show the total after the loop terminate

still new to c++

#include <iostream>

using namespace std;

int main()
{
    int num, sum = 0;
    // loop will run 10 times from i=0 to i=9
    for (int i = 0;i < 10;i++)
    {
        // get number from user
        
        cout << "Enter integer: "<< endl;

Am trying to asks the user for an integer ten times. Have the loop total the integers given. Show the total after the loop terminates

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here’s the remainder of your code:

        // get number from user
        std::cout << "Enter integer: " << endl;
        std::cin >> num;
        sum = sum + num;
        }
    } // End: for
    std::cout << "Total of all numbers: " << sum << endl;
    return 0;
}

The code above shows how to input a number, sum (total) the numbers and then print the total (sum).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading