//Devin Scheu CS1A Chapter 5, P. 294, #1
//
/**************************************************************
*
* CALCULATE SUM OF NUMBERS
* ____________________________________________________________
* This program determines the sum of all integers from 1 up to
* a specified positive integer.
*
* Computation is based on a loop summing integers from 1 to n:
* sum = sum + i (where i ranges from 1 to n)
* ____________________________________________________________
* INPUT
* inputNumber : The positive integer up to which the sum is calculated
*
* OUTPUT
* totalSum : The calculated sum
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
//Variable Declarations
int inputNumber; //INPUT - The positive integer up to which the sum is calculated
int totalSum; //OUTPUT - The calculated sum
//Prompt for Input
cout << "Enter a positive integer: ";
cin >> inputNumber;
//Input Validation
while (inputNumber < 0) {
cout << "\nError: Please enter a non-negative number: ";
cin >> inputNumber;
}
//Calculate Sum
totalSum = 0;
for (int i = 1; i <= inputNumber; i++) {
totalSum += i;
}
//Output Result
cout << "\n";
cout << left << setw(25) << "Entered Number:" << right << setw(15) << inputNumber << endl;
cout << left << setw(25) << "Sum:" << right << setw(15) << totalSum << endl;
return 0;
} //end of main()