From 39d26f0652791e00df074fb365dae0a20108f1a2 Mon Sep 17 00:00:00 2001 From: brookevaughan <31770267+brookevaughan@users.noreply.github.com> Date: Mon, 16 Oct 2017 09:05:43 -0500 Subject: [PATCH] Three Digit Ascend Descend Brooke Vaughan Period 1 I changed it to a do-while statement and added the int count in order to loop it exactly 30 times. I also edited the cout statements so it would output the number the user typed in and if it was ascending, descending, or neither. --- .../Source.cpp | 76 ++++++++++--------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Source.cpp b/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Source.cpp index b76ba2c..fc3fa39 100644 --- a/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Source.cpp +++ b/Three_Digit_Ascend_Descend_Selection/Three_Digit_Ascend_Descend_Selection/Source.cpp @@ -17,49 +17,55 @@ void pause() { } // MAIN void main() {// assigning variables + int count = 0; int x; - - cout << "Please choose a random 3 digit number";// alows user input of numbers. - cin >> x; + do { + cout << "Please choose a random 3 digit number";// alows user input of numbers. + cin >> x; + + + + int C = x % 10;//allows use of all three numbers as seperate variables + int B = (x / 10) % 10; + int A = (x / 100) % 10; + bool ascending; + bool descending; + - int C = x % 10;//allows use of all three numbers as seperate variables - int B = (x / 10) % 10; - int A = (x / 100) % 10; - bool ascending; - bool descending; - - ascending = A != B && B != C; - descending = ascending; //saying that if A does not equal B, and B does not equal C, then it is either ascending or descending. - if (A > B) { - ascending = false; - } - - else { - descending = false; - } - - if (B > C) { - ascending = false; - } + descending = ascending; //saying that if A does not equal B, and B does not equal C, then it is either ascending or descending. + if (A > B) { + ascending = false; + } - else { - descending = false; - } - if (ascending) { - cout << "The numbers are Ascending. "; - } - else if (descending) { - cout << "The numbers are Descending. "; - } - else { - cout << "The numbers are Neither ascending or descending. "; -} + else { + descending = false; + } + + if (B > C) { + ascending = false; + } + + else { + descending = false; + } + if (ascending) { + cout << x << " is ascending."; + } + else if (descending) { + cout << x << " is descending. "; + } + else { + cout << x << " is neither ascending or descending. "; + } + + pause(); + count = count + 1; + } while (count < 30); -pause(); }