// Castulo Jason Quintero CSC5 Chapter 5 homework, pg. 294 #1
//
/**************************************************************************
* Compute Sum of Numbers
* ________________________________________________________________________
* This program will accept user input for a number
* and will calculate the sum
* up to the number entered
* ________________________________________________________________________
* INPUT
* numInput : Selected positive integer
*
* OUTPUT
* totalSum : Sum of all integers
*
*************************************************************************/
#include <iostream>
using namespace std;
int main()
{
// Initialize variables
int numInput, // Selected positive integer
totalSum = 0; // accumulated sum of all numbers
// Input - User enters number
cout << "Enter a positive integer number: ";
cin >> numInput;
cout << endl;
// While loop to validate input
while(numInput <= 0){
cout << "Only positive integers accepted! ";
cout << "Try again: ";
cin >> numInput;
}
// for loop - adds numbers together
for(int i = 1; i <= numInput; i++){
totalSum += i;
}
// Display result
cout << "The sum of the numbers from 1 to ";
cout << numInput << " is " << totalSum << endl;
return 0;
}