Question

Write a C++ program that asks the user to enter in three numbers and displays the...

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).

Homework Answers

Answer #1


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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Design a program that asks user to enter any three numbers. The program should display the...
Design a program that asks user to enter any three numbers. The program should display the three numbers in ascending order. using python code please
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
Write a program that asks the user to enter a series of numbers separated by commas....
Write a program that asks the user to enter a series of numbers separated by commas. Here is an example of valid input: 7,9,10,2,18,6 The program should calculate and print the sum of all the numbers. Sample Run java NumberSum Enter·numbers·separated·by·commas:1,2,3↵ 6↵
write a C++ program that asks the user to enter 4 integer numbers then use if...
write a C++ program that asks the user to enter 4 integer numbers then use if ….. elseif ….. elseif ….. else to find the smallest number then display it.
Write a complete C++ program asking the user to enter numbers one by one. User enters...
Write a complete C++ program asking the user to enter numbers one by one. User enters only whole numbers 0 and 10. Once the user enters 0, then the program should print sum of only odd numbers entered by user prior to 0. A valid scenario given below: Enter a number: 5 Enter a number: 3 Enter a number: 2 Enter a number: 3 Enter a number: 8 Enter a number: 0 Sum of the odd numbers you entered is...
Write a program that asks a user to enter his/her phone number. Then remove all the...
Write a program that asks a user to enter his/her phone number. Then remove all the non-digits from the phone number and then display the digits entered. Hint: you may need to use the syntax “.isdigit()” in your program Sample run Example 1 Please enter your phone number?123-456/7891 1234567891 Example 2 Please enter your phone number?123(456)-7891 1234567891 Example 3 Please enter your phone number?987@654!4321 9876544321
python Write a program to find the largest value. Ask the user to enter three numbers....
python Write a program to find the largest value. Ask the user to enter three numbers. Compare them and report the largest one. [Hint: The user is free to enter any three numbers. Some or all of them may be the same. Take this into consideration when you compare the numbers.] The following are some examples. Enter first number: 7 Enter second number: 14 Enter third number: 10.5 The largest number is: 14.0 Enter first number: 17 Enter second number:...
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Write a NASM program that does the following: 1) Asks the user to enter three numbers...
Write a NASM program that does the following: 1) Asks the user to enter three numbers (each is a byte) A,B, and C 2) Adds up the numbers and stores the sum in variable D 3) Outputs the sum
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT