//Nathan Dominguez CSC5 Chapter 5, P. 294, #1
//
/*******************************************************************************
*
* Calculate the Sum of Numbers
* _____________________________________________________________________________
* This prorgam will take an input positive number and will loop to get the sum
* of all the numbers from 1 up to the input number. The program will not
* accept negative numbers that are input.
* _____________________________________________________________________________
* INPUT
* number : the number entered
*
* OUTPUT
* sum : the summation of all numbers stored
* FORMULA
* sum = sum + number
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int sum = 0; //OUTPUT-total of all numbers from 1 to number
int number; //INPUT-the number that was chosen
// display message
// input number
cout << "Enter a number greater than 0." << endl;
cin >> number;
for (int counter = 1; counter <= number; counter++)
// counter goes up by 1
// calculates sum
{
sum = sum + counter;
// counter++;
}
if (number < 1)
{ // display "invalid" message
cout << number << " is an invalid input." << endl;
}
else
// display output message
cout << "The sum of numbers 1 through " << number
<< " " << "is " << sum << "." << endl;
return 0;
}