Answer to Question #102601 in C++ for mlk

Question #102601
Write a program that will calculate the sum of numbers from 1 to 15. If the user enter a negative number the program will stop. (Use for loop with while or do-while).
1
Expert's answer
2020-02-10T03:50:47-0500
#include <iostream>
using namespace std;


int main()
{
    double sum = 0;


    for(int i=0;i<15;i++)
    {
        double number;
        do
        {
            cout << "Enter a number: ";
            cin >> number;
            cout << endl;


            sum += number;
            i++;


            if (i == 15)
            {
                break;
            }
        }while(number>=0);
    }


    cout << "sum = " << sum << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS