Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream> // gives access to cin, cout, endl, <<, >>, boolalpha, noboolalpha
#include <conio.h> // gives access to _kbhit() and _getch() for pause()

//Namespaces
using namespace std;

Expand All @@ -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..."
}
}