From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/SumOfIntegers/SumOfIntegers.cpp | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 C++/SumOfIntegers/SumOfIntegers.cpp (limited to 'C++/SumOfIntegers/SumOfIntegers.cpp') diff --git a/C++/SumOfIntegers/SumOfIntegers.cpp b/C++/SumOfIntegers/SumOfIntegers.cpp new file mode 100644 index 0000000..b917243 --- /dev/null +++ b/C++/SumOfIntegers/SumOfIntegers.cpp @@ -0,0 +1,79 @@ +// Name: msglm +// Date: +// Program Name: +// Description: + + +#include +#include +#include +using namespace std; + +// Named constants + +int main() { + + //Variable declaration + int numOfNums; + int num; + int sum; + int iterator; + char choice; + //Program title and description for the user + cout << "Title: Sum of Integers" << endl << "Description: Takes user input and provides of sum of said input. only 2 to 10 numbers and the number must be greater than 0 but less than 1000" << endl; + + do { + + // User input + do + { + cout << "How many integers do you wish to add?: \n"; + cin >> numOfNums; + + if (!cin) { + cout << "That is not an integer. Program will terminate.\n"; + return 1; + } + + if (numOfNums < 2) { + cout << "Addition requires at least two values" << endl; + } + + if (numOfNums > 10) { + cout << "This program can only add up to 10 values" << endl; + } + } while(numOfNums < 2 || numOfNums > 10 || !cin); + + // Calculations + for(iterator=1; iterator <= numOfNums; iterator++) { + do { + cout << "Enter an integer (in a range from 0 to 1000): \n"; + cin >> num; + if (!cin) { + cout << "That is not an integer. Program will terminate.\n"; + return 1; + } + if(num<0 || num>1000){ + cout << "Invalid number. Only numbers in the range of 0 to 1000 are accepted\n\n"; + } + + }while(num < 0 || num > 1000); + sum = sum + num; + + + // Output to the screen + cout << "\nThe sumnation of " << numOfNums << " integer values you inputted is: " << sum << endl; + + cout << "Do you want to run the program again? (Y/N)" << endl; + cin >> choice; + cout << endl << endl; + } + } while(choice == 'Y' || choice == 'y'); + cout << "Terminating"; +} +/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + -- cgit v1.2.3