This is a very simple app I am trying to do. How else would sum up the total of the number the user entered? Example if the user enters 10, the loop will find the sum of 1,2,3,4,5.....10. Here is my code and I spent few hours on to come up with this simple code.
//this will add up the number you entered
# include <iostream>
using namespace std;
int main()
{
int num; //to hold the number to be sumed up
int input; //this is an accumulator
int maxNum; //the maximum number the user entered
int total; //this will hold the total of the number the user typed in
cout << "Enter the number and I will add them up<<\n";
cin >> maxNum;
for (num=1; maxNum=1; input++)
{
cout <<"You entered" <<maxNum<< endl;
cout <<"See the total below" << endl;
cout << (total += input) << endl;
maxNum++;
}
return 0;
}
the book says I can use the for loop if the number of iteration is known. In this case the iteration depends on the number the user entered which is stored in maxNum variable. Which operator I am using is wrong here or the whole structure of my code is messed up? Please help!