Question

In: Computer Science

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

Solutions

Expert Solution


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


Related Solutions

in C++, Write a program that asks the user to enter 6 numbers. Use an array...
in C++, Write a program that asks the user to enter 6 numbers. Use an array to store these numbers. Your program should then count the number of odd numbers, the number of even numbers, the negative, and positive numbers. At the end, your program should display all of these counts. Remember that 0 is neither negative or positive, so if a zero is entered it should not be counted as positive or negative. However, 0 is an even number....
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
write a c program that asks the user to enter any two intger numbers and each...
write a c program that asks the user to enter any two intger numbers and each number consist of four digits. your program should check whether the numbers are four digits or not and in case they are not a four digit number the program should print a message and exit otherwise it should do the following print a mnew as follows    select what you want to do with the number 1-3: 1-print grreatest common divisor (gcd)of the two...
write a C program that asks the user to enter numbers and finds maximum among them
write a C program that asks the user to enter numbers and finds maximum among them
The program asks user to enter three integers, and the displays a message indicating whether the...
The program asks user to enter three integers, and the displays a message indicating whether the numbers are in sequential order, in reverse order or in neither order. Find the errors and correct the program codes in the if comparison expressions. (10 points) 1.     using System; 2.     using static System.Console; 3. 4.     class Sorting 5.     { 6.              static void Main() 7.              { 8.                       int num1, num2, num3; 9.                       string snum1, snum2, snum3; 10.                    Write ("Enter first number "); 11.                    snum1...
Write a C program that asks the user to enter 15 integer numbers and then store them in the array.
Write a C program that asks the user to enter 15 integer numbers and then store them in the array. Then, the program will find the second largest element in array and its index without sorting the array. For example, In this array {-55,-2,1, 2, -3, 0, 5, 9, 13, 1, 4, 3, 2, 1, 0}, the second largest element is 9 [found at index 7].
Write a program that asks the user to enter an array of random numbers, then sort...
Write a program that asks the user to enter an array of random numbers, then sort the numbers (ascending order), then print the new array, after that asks the user for a new two numbers and add them to the same array and keep the array organization. (c++ ) (using while and do while loops)
Write a python program that asks the user to enter a string containing numbers separated by...
Write a python program that asks the user to enter a string containing numbers separated by commas, e.g., s = '1.23,2.4,3.123', Your program should then calculate and print the sum of the numbers entered. Hint: you need to iterate over the string searching for the commas, i.e. their index. The first number is obtained by slicing between the start of the string and the index of the first comma. The second number is between the last comma and the next...
Write a program in C++ that asks the user for his/her Taxable Income and displays the...
Write a program in C++ that asks the user for his/her Taxable Income and displays the Income Tax owed. Use the following table to calculate the Income Tax: Taxable Income Tax Rate $0 to $9,225 / 10% $9,226 to $37,450 / $922.50 plus 15% of the amount over $9,225 $37,451 to $90,750 / $5,156.25 plus 25% of the amount over $37,450 $90,751 to $189,300 / $18,481.25 plus 28% of the amount over $90,750 $189,301 to $411,500 / $46,075.25 plus 33%...
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT