diff --git a/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Pranay_Srivastava_John_Bui_Three_Digit_Ascend_Descend_Selection.cpp b/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Pranay_Srivastava_John_Bui_Three_Digit_Ascend_Descend_Selection.cpp index 1d01482..c722e36 100644 --- a/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Pranay_Srivastava_John_Bui_Three_Digit_Ascend_Descend_Selection.cpp +++ b/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Pranay_Srivastava_John_Bui_Three_Digit_Ascend_Descend_Selection.cpp @@ -4,10 +4,6 @@ Assignment Name: Three_Digit_Ascend_Descend_Selection State whether the digits of a 3-digit number are ascending, descending, or neither using stored variables. */ -//Libraries -#include // gives access to cin, cout, endl, <<, >>, boolalpha, noboolalpha -#include // gives access to _kbhit() and _getch() for pause() - //Namespaces using namespace std; @@ -20,24 +16,33 @@ void pause() { } //MAIN -void main(){ - int n; +void main() { + int x; //**SLIGHTLY EDITED VAR NAME** cout << "Enter a positive 3 digit integer : "; - cin >> n; // 'n' is the variable that stores the three digit number that the user types in. + cin >> x; // 'n' is the variable that stores the three digit number that the user types in. + - int a = n / 100; // Isolates the digit in the 100th's place. - int b = (n % 100) / 10; // Isolates the digit in the 10th's place. - int c = n % 10; // Isolates the digit in the 1's place. + for (int i = 0; i < 30; i++) { //**ADDED FOR LOOP FOR 30 REPETITONS** - if (a > b && b > c) { - cout << "Descending" << endl; - } // If the digits of 'n' are presented in a descending order from left to right, print 'descending'. - else if (a < b && b < c) { - cout << "Ascending" << endl; - } // If the digits of 'n' are presented in a ascending order from left to right, print 'ascending'. - else { - cout << "Neither" << endl; - } // If the digits of 'n' aren't presented in either a descending or ascending order from left to right, print 'neither'. + int a = x / 100; // Isolates the digit in the 100th's place. + int b = (x % 100) / 10; // Isolates the digit in the 10th's place. + int c = x % 10; // Isolates the digit in the 1's place. + if (a > b && b > c) { + cout << x << " is Descending" << endl; //**SLIGHTLY EDITED WORDING** + cout << "Enter another positive 3 digit integer : "; //lets user input another integer + cin >> x; + } // If the digits of 'n' are presented in a descending order from left to right, print 'descending'. + else if (a < b && b < c) { + cout << x << " is Ascending" << endl; + cout << "Enter another positive 3 digit integer : "; + cin >> x; + } // If the digits of 'n' are presented in a ascending order from left to right, print 'ascending'. + else { + cout << x << " is neither Ascending nor Descending" << endl; + cout << "Enter another positive 3 digit integer : "; + cin >> x; + } // If the digits of 'n' aren't presented in either a descending or ascending order from left to right, print 'neither'. + } pause(); // Ends function, prints "Press any key to continue..." -} \ No newline at end of file +}