From 5632f54bd0cfca6d0a63d2743a90e71d8f830876 Mon Sep 17 00:00:00 2001 From: Yofriend123 <31861826+Yofriend123@users.noreply.github.com> Date: Thu, 12 Oct 2017 12:22:13 -0500 Subject: [PATCH] Assignment 4 Modified the Assignment 3 project by including comments and a loop for 30 numbers. John Bui --- .../Ascending_Descending1.cpp | 67 ++++++++++++------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/Ved Nigam_3_Digit_Ascending_Descending_Neither/Ascending_Descending1.cpp b/Ved Nigam_3_Digit_Ascending_Descending_Neither/Ascending_Descending1.cpp index 1cc1788..a531126 100644 --- a/Ved Nigam_3_Digit_Ascending_Descending_Neither/Ascending_Descending1.cpp +++ b/Ved Nigam_3_Digit_Ascending_Descending_Neither/Ascending_Descending1.cpp @@ -1,14 +1,26 @@ +/* Overall changes: +Added date +Comments on printing ascending, descending, and neither to clarify what happens +Altered the ints to decrease the amount of lines +Comments on cin and pause to clarify what happens +Added comments for what is included in the libraries +*/ + /* -Ved Nigam-Period 3-Computer Science 1 +Ved Nigam-Period 3-Computer Science 1 October 5, 2017 In this assignment, we will split a 3 digit number into 3 different numbers with the same characters as the 3 digit number. We will then run a tets to see if the numbers are "Descending," "Ascending," or "Neither." */ +// Added date //Libraries -#include -#include +#include // gives access to cin, cout, endl, <<, >>, boolalpha, noboolalpha +#include // gives access to _kbhit() and _getch() for pause() +// Added comments + //Namespaces using namespace std; + //Functions void pause() { cout << "Press Any Key to Continue . . ."; @@ -18,26 +30,35 @@ void pause() { } void main() { - int x; - int a; - int b; - int c; - - cout << "Enter a 3 Digit Number . . ." << endl; - cin >> x; - c = x % 10; - b = x / 10 % 10; - a = x / 100; - - if (a > b && b > c) { - cout << "Descending" << endl; - } - else if (a < b && b < c) { - cout << "Ascending" << endl; - } - else { - cout << "Neither" << endl; + for (int i = 0; i < 30; i++) { + int x; + + cout << "Enter a 3 Digit Number . . ." << endl; + cin >> x; // 'x' is the variable that stores the three digit number that the user types in. + // Added comments + + int c = x % 10; // Isolates the digit in the 1's place + int b = x / 10 % 10; // Isolates the digit in the 10th's place + int a = x / 100; // Isolates the digit in the 100th's place + // Altered : Placed int c, int b, and int a in one area + + if (a > b && b > c) { + cout << "Descending" << endl; + } // If the digits of 'x' are presented in a descending order from left to right, print 'descending'. + // Added comment for what it does + else if (a < b && b < c) { + cout << "Ascending" << endl; + } // If the digits of 'x' are presented in a ascending order from left to right, print 'ascending'. + // Added comment for what it does + else { + cout << "Neither" << endl; + } // If the digits of 'x' aren't present in either a descending or ascending order from left to right, print 'neither' + // Added comment for what it does + + pause(); // Ends function, prints "Press any key to continue..." + // Added comment for what it does } - pause(); } + +