Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order.
If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program.
Be sure to think about all the possible cases of three numbers.
Be sure to test all possible paths.
Sample Runs:
NOTE: not all possible runs are shown below.
Sample Run 1
Welcome to the order numbers program
Please enter in a number... 8
Please enter in a number... 8
Please enter in a number... 8
All the numbers are equal.
Sample Run 2
Welcome to the order numbers program
Please enter in a number... 8
Please enter in a number... 9
Please enter in a number... 3
3
8
9
1. No global variables (variables outside of main() )
2. All input and output must be done with streams, using the
library iostream
3. You may only use the iostream and iomanip libraries (you do not
need any others for these tasks)
4. NO C style printing is permitted. (Aka, don’t use printf). Use
cout if you need to print to the screen.
5. When you write source code, it should be readable and
well-documented (comments).
Code:
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin >> a >> b >> c;
//taking 3 numbers input from
user
if(a==b==c)
//if all numbers are equal
cout << "All the numbers are
equal."<< endl;
else if(a<=b && b<=c)
//if a<b<c if a<=b<c or a<b<=c
cout << a << endl
<< b << endl << c <<endl;
else if(a<=c && c<=b)
//if a<c<b or a<=c<b or a<c<=b
cout << a << endl
<< c << endl << b << endl;
else if(b<=c && c<=a)
//if b<c<a or b<=c<a or b<c<=a
cout << b << endl
<< c << endl << a << endl;
else if(b<=a && a<=c)
//if b<a<c or b<=a<c or b<a<=c
cout << b << endl
<< a << endl << c << endl;
else if(c<=a && a<=b)
//if c<a<b or c<=a<b or c<a<=b
cout << c << endl
<< a << endl << b << endl;
else
//if c<b<a or c<=b<a or c<b<=a
cout << c << endl
<< b << endl << a << endl;
}
Get Answers For Free
Most questions answered within 1 hours.