Question: // Finish the following program which adds up all integers from 0 to // the user's given number inclusively using a While Loop. The total
// Finish the following program which adds up all integers from 0 to // the user's given number inclusively using a While Loop. The total should be // assigned to the variable 'total'. #includeusing namespace std; int main() { int number; int total = 0; int counter = 0; //initialize the variable // user enters a number cout << "Enter a positive integer to find the summation of "; cout << "all numbers from 0 to the given number up to 100." << endl; cin >> number; // check for invalid user input if (number < 1 || number > 100) { cout << "Invalid Input" << endl; return -1; // terminate program } // TODO - add your code here. // hint: increment a counter variable inside the loop. cout << "Your total is :" << total; return 0; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
