Question: #include using namespace std; int main() { int n, total = 0; cin >> n; total = 0; while (n > 0) { total =

#include
using namespace std;
int main() {
int n, total = 0;
cin >> n;
total = 0;
while(n > 0)
{
total = total + n;
n--;
} cout
return 0;
}
I did it this way but I can't seem to get it right. I am trying to answer it with C++ "while loops. "
Create a program which will implement the sum of the numbers between 1 and n where n is an integer. When completed, the program will allow the user to input a positive integer (n) then the program will add all numbers between 1 and n (including n) and output the sum. For example, if the user enters 8 then the program will sum the numbers 1 through 8 and will output the sum. Test your program with the following inputs: a. 8 (sum is 36) b. 75 (sum is 2850) c. 100 (sum is 5050)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
