1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
using namespace std;
int main()
{
// User prompt and three values.
double x, y, z; // x, y, and z are the values inputted by the user.
cout << "Please enter three different values, then press enter.\n";
cin >> x >> y >> z;
cout << "\n";
// Determining user's value input
if (x == y && y == z)
{
cout << "Error. Please restart the program and enter 3 distinct values.\n";
}
else
{
// Value order menu
char order;
cout << "Press A for ascending order or D for descending order, then press enter.\n";
cin >> order;
cout <<"\n";
if (order == 'A')
{
cout << "Now ranking in ascending order...\n";
if (x < y && y < z)
{
cout << x << ", " << y << ", " << z << ".\n";
}
else if (x < z && z < y)
{
cout << x << ", " << z << ", " << y << ".\n";
}
else if (y < x && x < z)
{
cout << y << ", " << x << ", " << z << ".\n";
}
else if (y < z && z < x)
{
cout << y << ", " << z << ", " << x << ".\n";
}
else if (z < y && y < x)
{
cout << z << ", " << y << ", " << x << ".\n";
}
else if (z < x && x < y)
{
cout << z << ", " << x << ", " << y << ".\n";
}
}
else if (order == 'D')
{
cout << "Now ranking in descending order...\n";
// WHY IS IT NOT WORKING??
if (x > y && y > z)
{
cout << x << ", " << y << ", " << z << ".\n";
}
else if (x > z && z > y)
{
cout << x << ", " << z << ", " << y << ".\n";
}
else if (y > x && x > z)
{
cout << y << ", " << x << ", " << z << ".\n";
}
else if (y > z && z > x)
{
cout << y << ", " << z << ", " << x << ".\n";
}
else if (z > y && y > x)
{
cout << z << ", " << y << ", " << x << ".\n";
}
else if (z > x && x > y)
{
cout << z << ", " << x << ", " << y << ".\n";
}
}
else
{
cout << "Error. Please enter either A or D to make your choice.";
}
}
return 0;
}
|