Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We\'re going to write a simple calculator that adds. Assume the user will input

ID: 3649180 • Letter: W

Question

We're going to write a simple calculator that adds. Assume the user will input integers one by one from the Console, with the last integer always 0. Write a program that outputs the sum to the Console. For example, if the user inputs the integers 10 -2 5 0, your program should output 13. If the user inputs only 0, your output should be 0.

Instructor's notes: The solution here requires a different approach that the others, so think... For example, how do you initialize your loop variable? By inputting the first number from the Console keyboard...

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
int main()
{int n,sum=0;
cout<<"Enter a number(0 to output the sum): ";
cin>>n;
while(n!=0)
   {sum+=n;
    cout<<"Enter a number(0 to output the sum): ";
    cin>>n;
    }
cout<<"The sum is "<<sum<<endl;
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote