//Nicolas Ruano CS1A Chapter 5, P. 294, #1
//
/**************************************************************
*
* COMPUTE THE SUMMATION OF INTEGERS FROM ONE TO A GIVEN LIMIT.
* _____________________________________________________________
* This program computes the sum of all consecutive integers from
* one (1) up to a user-specified limit. It prompts the user to
* enter a positive whole number and, if a negative value is
* provided, repeatedly requests a valid entry. Once a positive
* number is entered, the program uses a loop to add each number
* from one to * the specified limit and then displays the
* accumulator result to the user.
*
* Computation is based on the formula:
* Natural numbers Sigma from 0 to the user’s specified index.
* ____________________________________________________________
* INPUT
* number
*
*
* OUTPUT
* sum
*
**************************************************************/
#include <iostream> // For input and output
using namespace std;
int main() {
int number; // Variable to store user input
int sum = 0; // Variable to store the total sum
// --- Step 1: Ask for a positive number ---
cout << "Enter a positive number: 1\n";
cin >> number;
// --- Step 2: Input Validation Loop ---
while (number < 0) {
cout << "Please enter a positive number: 50\n";
cin >> number;
}
// --- Step 3: Calculate the Sum using a loop ---
for (int i = 1; i <= number; i++) {
sum = sum + i; // Add each number to the sum
}
// --- Step 4: Display the result ---
cout << "The total sum is: 60\n" << sum << endl;
// --- Step 5: End Program ---
return 0;
}