//Eun Hyeung Lucia Lee CSC5 Chapter 5, P. 295, #1
//
/**************************************************************
* CALCULATE SUM
* ____________________________________________________________
* This program prompts the user for a positive integer value.
* The program then computes the sum of all the integers from
* 1 to the input integer.
*
* No negative starting numbers are accepted.
* ____________________________________________________________
* INPUT
* max_num : Positive integer that will be
* used as max for sum
*
* OUTPUT
* sum : Sum of all integers added to the
* max_num
* PROCESSING
* count : Counter integer set to 1 that
* controls the loop by comparison
* to the max_num
**************************************************************/
#include <iostream>
using namespace std;
int main()
{
// Define variables
int count; // PROCESSING - Counter for loop
int max_num; // INPUT - Positive integer used as max
int sum = 0; // OUTPUT - Total sum of all integers based on max
// Ask for user input
cout << "Please enter a positive integer: " << endl;
cin >> max_num;
// For invalid inputs (negative)
while (max_num <=0)
{
cout << "<Error: Please input a POSITIVE integer>" << endl;
cin >> max_num;
}
// For valid inputs
for (count = 1; count <= max_num && max_num >= 1; count++)
{
// Display sums
cout << count << " + " << sum << " = ";
sum += count;
cout << sum << endl; // Updated sum
}
return 0;
}