Question

Using C++ Design a program that Prompts the user to enter in 4 numbers, then have...

Using C++ Design a program that Prompts the user to enter in 4 numbers, then have the program arrange the numbers entered in Ascending order using "if" statements to complete the task...

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We can use if statements to compare the integers and we have to use a temporary integer to swap them.

C++ code

#include <iostream>

using namespace std;

int main() {
int a,b,c,d,temp;
cout<<"Enter 4 numbers: ";
cin>>a>>b>>c>>d;
if (a > c) { temp = a; a = c; c = temp; }
if (b > d) { temp = b; b = d; d = temp; }
if (a > b) { temp = a; a = b; b = temp; }
if (c > d) { temp = c; c = d; d = temp; }
if (b > c) { temp = b; b = c; c = temp; }
cout<<"The numbers in sorted format are: ";
cout<<a<<" "<<b<<" "<<c<<" "<<d;
}

The output is

Result compiled and executed in 7.847 sec(s) Enter 4 numbers: 5 3 42 The numbers in sorted format are: 2 3 4 5

Add a comment
Know the answer?
Add Answer to:
Using C++ Design a program that Prompts the user to enter in 4 numbers, then have...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Prompts the user to enter 5 numbers. Once the user has entered the 5...

    In C++ Prompts the user to enter 5 numbers. Once the user has entered the 5 numbers, the program should calculate and display the average of the 5 numbers.and The program prompts the user for one number at a time, without using for

  • Write a C++ program that prompts the user to enter two numbers. Then prompt the user...

    Write a C++ program that prompts the user to enter two numbers. Then prompt the user to select from the following options: a. Add the numbers. b. Multiply the numbers. c. Terminate the program Use the appropriate control structures (loops, if else, switch-case, etc) to make your program as short and efficient as possible. Minor syntax errors are forgiven in this exercise; just focus on the correct structure, declarations and sequence of instructions

  • Design a Python program that prompts the user to enter "yes" or "no" and validates the...

    Design a Python program that prompts the user to enter "yes" or "no" and validates the input. (Use a case-insensitive comparison) and another Python program that prompts the user to enter a number in the range of 1 through 100 and validates the input

  • The Assignment Design a Visual Logic flowchart for a program that prompts the user to enter...

    The Assignment Design a Visual Logic flowchart for a program that prompts the user to enter ten numbers one at a time. Use Console I/O (not the GUI interface). After the user has entered all ten number the program will then print out the total of those ten number and quit. Here is one example of what the program might look like when run: Please enter a number: 5 Please enter a number: 10 Please enter a number: 2 Please...

  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • a. Design the logic for a program that allows a user to enter 12 numbers, then...

    a. Design the logic for a program that allows a user to enter 12 numbers, then displays them in the reverse order of entry. b. Modify the reverse-display program so that the user can enter any amount of numbers up to 12 until a sentinel value is entered. ( I really could use more of a pseudocode rather than actual code. also an explanation of each step. The answer I got last time was just c++ code that including a...

  • Write a complete java program that prompts the user for their name and two numbers. The...

    Write a complete java program that prompts the user for their name and two numbers. The correct java methods and parameters must be passed to find the length of the name entered and return “TRUE” if the sum of numbers is even, or FALSE if the sum of numbers is odd: Notes included in the program Sample Program Please enter a name and I will tell you the length of the name entered John Then length of the name John...

  • Using C# Exercise #3: Design and implement a program (name it CheckPoint) that prompts the user...

    Using C# Exercise #3: Design and implement a program (name it CheckPoint) that prompts the user to enter the x-coordinate then y-coordinate of a point (in a Cartesian plane) as integer values. The program prints out the entered values followed by the location of the point on the plane. The possibilities for a point are: the origin point, on the x-axis, on the y-axis, in the first quadrant, in the second quadrant, in the third quadrant, or in the fourth...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT