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...
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 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%...
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 C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT