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
@@ -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 <iostream>// gives access to cin, cout, endl, <<, >>, boolalpha, noboolalpha
#include <iostream> // gives access to cin, cout, endl, <<, >>, boolalpha, noboolalpha

#include <conio.h> // gives access to _kbhit() and _getch() for pause()

Expand All @@ -24,6 +24,8 @@ void pause() {

cout << "Press any key to continue . . .";



while (!_kbhit());

_getch();
Expand All @@ -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
}