From 67f96ec999509affd0739dfeb67d0383893f1409 Mon Sep 17 00:00:00 2001 From: noosratr <31855435+noosratr@users.noreply.github.com> Date: Fri, 27 Oct 2017 09:56:07 -0500 Subject: [PATCH] assignment 4 --- .../Three_Digit_Ascend_Descend_Selection.cpp | 81 ++++++------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection.cpp b/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection.cpp index 6b524ef..09cc595 100644 --- a/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection.cpp +++ b/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection.cpp @@ -1,16 +1,16 @@ /* -Sam Bryant & Dorothy Bui - 10/5/17 - 2 +Nikhil Goyle - 10/5/17 2 -Assignment Name : Three digit Ascend Descend Selection +Program Problem 3 : * -Take in 3 digits from the user, seperate those digits and say whether they ascend descend or neither. +Determine whether a number is ascending or descending */ // Libraries -#include // gives access to cin, cout, endl, <<, >>, boolalpha, noboolalpha +#include // gives access to cin, cout, endl, <<, >>, boolalpha, noboolalpha #include // gives access to _kbhit() and _getch() for pause() @@ -24,6 +24,8 @@ void pause() { cout << "Press any key to continue . . ."; + + while (!_kbhit()); _getch(); @@ -35,63 +37,32 @@ void pause() { void main() { - //define variables: - int userNumber; - int digit1; - int digit2; - int digit3; - - //ask for variable - - cout << "Give me a three digit number!" << endl; - - // take in variable - - cin >> userNumber; - - // seperate number to 3 digits; - - digit1 = userNumber / 100; //int division - digit2 = (userNumber / 10) % 10; - digit3 = userNumber % 10; - - // removed section because it was unnecessary - //calculate ascending descending or neither: + int x; + int A; + int B; + int C; - if (digit1 > digit2 && digit2 > digit3) { - cout << "Your number is descending!" << endl; - } - else if (digit1 < digit2 && digit2 < digit3) { - cout << "Your number is ascending!" << endl; - } - else { - cout << "Your number is neither ascending nor descending." << endl; - } + for (int i = 30; i < 30; i++) { + cout << "Give me a 3-digit number: " << endl; + cin >> x; - for (int i = 1; i < 30; i++) { + C = x % 10; + B = (x / 10) % 10; + A = (x / 100); - cout << "Give me a three digit number!" << endl; - - // take in variable - - cin >> userNumber; - - digit1 = userNumber / 100; //int division - digit2 = (userNumber / 10) % 10; - digit3 = userNumber % 10; - - // removed section because it was unnecessary - //calculate ascending descending or neither: - if (digit1 > digit2 && digit2 > digit3) { - cout << "Your number is descending!" << endl; + if (A > B && B > C) { + cout << x << " is descending" << endl; } - else if (digit1 < digit2 && digit2 < digit3) { - cout << "Your number is ascending!" << endl; + + else if (C > B && B > A) { + cout << x << " is ascending" << endl; } + else { - cout << "Your number is neither ascending nor descending." << endl; + + cout << x << " is neither ascending or descending" << endl; } - } - + + } pause(); // pauses to see the displayed text }