// Drew Duffey CSC5 Chapter 5, P.294, #1
//
/*******************************************************************************
*
* CALCULATE SUM
* _____________________________________________________________________________
* This program will calculate the sum of all numbers up to a specific positive
* number, also known as a termial.
* _____________________________________________________________________________
* INPUT
* number : The number the user wants to find the termial of
*
* OUTPUT
* sum : The sum of all the positive numbers below and including the number
*
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int number; //INPUT - The number the user wants to find the terminal value
//of
float sum; //OUTPUT - The sum of all the positive numbers below and
//including the number
//Prompt the user to input a positive number, giving an error if the number
//is negative.
cout << "Please enter a positive whole integer: ";
cin >> number;
//Input Validation
if (number < 0)
{
cout << "\nInvalid number. Please try again.";
return 0;
}
//Calculate sum
sum = (number*(number+1))/2;
cout << "\nThe termial of that number is " << sum;
return 0;
}
Ly8gRHJldyBEdWZmZXkJCQlDU0M1CQkJQ2hhcHRlciA1LCBQLjI5NCwgIzEKLy8gCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqIAogKiBDQUxDVUxBVEUgU1VNCiAqIF9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCiAqIFRoaXMgcHJvZ3JhbSB3aWxsIGNhbGN1bGF0ZSB0aGUgc3VtIG9mIGFsbCBudW1iZXJzIHVwIHRvIGEgc3BlY2lmaWMgcG9zaXRpdmUKICogbnVtYmVyLCBhbHNvIGtub3duIGFzIGEgdGVybWlhbC4KICogX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KICogSU5QVVQKICogbnVtYmVyCTogVGhlIG51bWJlciB0aGUgdXNlciB3YW50cyB0byBmaW5kIHRoZSB0ZXJtaWFsIG9mCiAqIAogKiBPVVRQVVQKICogc3VtCQk6IFRoZSBzdW0g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