I have an assignment due tonight for a beginner programming class. My instructions are:
(sum) Create a program that will output the sum of all of the numbers from 1 to 100.
I used an old program I had to do as a template, but my code makes the total number of inputs print out at the end, instead of the sum of however many numbers are input. How can I correct this?
I know it's a simple little mistake, and were my assignment not due tonight I wouldn't be asking.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
float inputNumber, totalSum=0;
cout<<"Please input a number, or enter 0 to stop."<<endl;
cout<<endl;
cin>>inputNumber;
if (inputNumber !=0)
{
while (inputNumber !=0)
{
totalSum++;
cin>>inputNumber;
}
}
totalSum += inputNumber;
cout<<"The sum of all numbers entered is:"<<totalSum<<endl;
system ("pause");
return 0;
}