//Andres Guzman CSC5 Chapter 5, P. 294, #1
//
/*******************************************************************************
*
* DISPLAY SUM OF NUMBER
* ______________________________________________________________________________
* This program will display a sum of integers after a inputted integers
*
* Computation is based on the formula:
*
* Input Validation: num <= 0
*
* total += sum, sum++
* ______________________________________________________________________________
* INPUT
*
* num = The inputed integer by the programmer
*
* OUTPUT
*
* sum = All the integers prior to the input.
* total = The added sums
*
*******************************************************************************/
#include <iostream>
using namespace std;
int main ()
{
int num; // Holds the input integer
int sum = 1; // counter starting from the first positive number
int total = 0; //Accumulates the added total of sum
//
//Display input prompt
cout << "Enter a positive integer value: ";
cin >> num;
//
//Initalize While Loop & nested While Loop
while (num <= 0) //if the number is 0 or less, displays invalid.
{
cout << "\nInvalid value, please enter a positive integer value.\n";
cout << "\nEnter a positive integer value: ";
cin >> num;
}
while (sum <= num) //Sum will loop until it reachs the inputed integer
{
total += sum; //Adds up the sums into total for a final number
sum++;
}
//
//Output results
cout << "\nSum: " << total; //Outputs the sum of all the numbers up to the
//integer added
}