Question

Please write a C++ program that will accept 3 integer numbers from the user, and output...

Please write a C++ program that will accept 3 integer numbers from the user, and output these 3 numbers in order, the sum, and the average of these 3 numbers. You must stop your program when the first number from the user is -7.

Design Specifications:

(1) You must use your full name on your output statements.

(2) You must specify 3 prototypes in your program as follows:

int max(int, int, int); // prototype to return maximum of 3 integers

int min(int, int, int); // prototype to return minimum of 3 integers

int mid(int, int, int); // prototype to return middle of 3 integers

(3) You must define the above 3 integer functions properly in your program.

(4) You must NOT use any C++ existing functions in your program.

(4) You must fully test your program to make sure these 3 functions are working perfectly for any data.

===========================================================================.

The following is a sample standard test, which must be your test case #1. You must also do test case #2and test case #3 with different set of data to prove that your program is working perfectly for any data.

Please enter 3 integer numbers in any order (-7 to stop) :  7 6 5

You just entered 3 numbers: 7, 6, 5

These 3 numbers in order are 5, 6, 7

The sum of these 3 numbers is 18

The average of these 3 numbers is 6

Please enter 3 integer numbers in any order (-7 to stop) :  3 4 5

You just entered 3 numbers: 3, 4, 5

These 3 numbers in order are 3, 4, 5

The sum of these 3 numbers is 12

The average of these 3 numbers is 4

Please enter 3 integer numbers in any order (-7 to stop) :  5 9 7

You just entered 3 numbers: 5, 9, 7

These 3 numbers in order are 5, 7, 9

The sum of these 3 numbers is 21

The average of these 3 numbers is 7

Please enter 3 integer numbers in any order (-7 to stop) :  9 9 9

You just entered 3 numbers: 9, 9, 9

These 3 numbers in order are 9, 9, 9

The sum of these 3 numbers is 27

The average of these 3 numbers is 9

Please enter 3 integer numbers in any order (-7 to stop) :  -7 0 0

Thank you for playing this SUPER game designed by ********!

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

#include <iostream>

using namespace std;

void printOrder(int a,int b,int c){

if (a>b && b>c) {

cout<<c<<" "<<b<<" "<<a;

}

else if (a>c && c>b)

cout<<b<<" "<<c<<" "<<a;

else if (b>a && a>c)

cout<<c<<" "<<a<<" "<<b;

else if (b>c && c>a)

cout<<a<<" "<<c<<" "<<b;

else if (c>a && a>b)

cout<<b<<" "<<a<<" "<<c;

else cout<<a<<" "<<b<<" "<<c;

cout<<endl;

}

int main() {

int n1,n2,n3;

double sum=0,avg;

while(true){

cout<<"Please enter 3 integer numbers in any order (-7 to stop) : ";

cin>>n1;

if(n1==-7)

break;

cin>>n2;

cin>>n3;

sum=n1+n2+n3;

avg=sum/3;

cout<<"You just entered 3 numbers: "<<n1<<" "<<n2<<" "<<n3<<endl;

cout<<"These 3 numbers in order are: ";

printOrder(n1,n2,n3);

cout<<"The sum of these 3 numbers is: "<<sum<<endl;

cout<<"The average of these 3 numbers is: "<<avg<<endl;

}

}

Add a comment
Know the answer?
Add Answer to:
Please write a C++ program that will accept 3 integer numbers from the user, and output...
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 this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • Python Script format please! 1. Write a script that takes in three integer numbers from the...

    Python Script format please! 1. Write a script that takes in three integer numbers from the user, calculates, and displays the sum, average, product, smallest, and largest of the numbers input. Important things to note: a. You cannot use the min() or max() functions, you must provide the logic yourself b. The calculated average must be displayed as an integer value (ex. If the sum of the three values is 7, the average displayed should be 2, not 2.3333). Example:...

  • Write a program that prompts the user for positive integers, only stopping when a negative integer...

    Write a program that prompts the user for positive integers, only stopping when a negative integer or zero is given. The program should then print out how many of the positive integers were odd. Example: Enter a positive integer (0 or negative to stop): 9 Enter a positive integer (0 or negative to stop): 4 Enter a positive integer (0 or negative to stop): 7 Enter a positive integer (0 or negative to stop): -3 You entered 2 odd integers....

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

  • This is a C program. please help me to write a pseudocode of the program ....

    This is a C program. please help me to write a pseudocode of the program . also, I want the program In a do...while loop and the screen output should look like in the picture. please help me. 3.1. Write a program that asks the user to continue to enter two numbers (at a time). For each pair of numbers entered, the program calculates the product of those two numbers, and then accumulate that product. For each pair of numbers...

  • Please use Python Exercise 1 Create a program named sentinel_loop using break. This program should implement...

    Please use Python Exercise 1 Create a program named sentinel_loop using break. This program should implement functionality that is the same as the Part 1 tutorial example, except for the following differences: • • This program should count even and odd integers. This program should report counts of even and odd integers. Remember that even integers can be identified using the test condition: value % 2 == 0 Remember to test your code for appropriate behavior when the user signals...

  • 2. Write a program that reads N integer numbers of array from the user and then...

    2. Write a program that reads N integer numbers of array from the user and then displays the sum, max number and the numbers of the array use four subroutines ( Read_Array(), Calculate_Sum(), Find_Max() and Display_Array()). Here is sample output Please enter number of elements: 4 Please enter the required numbers: 50 100 150 20 The entered numbers are: 50 100 150 20 Sum is : 320 Max is 150 by Mpsi ,sum and max to call subroutine and retrieve...

  • write a c program for the above Write a program which prompts the user to enter...

    write a c program for the above Write a program which prompts the user to enter three integers (data type int) and then calculates the arithmetic average as a decimal number and prints the value with two decimal digits. If you have time also calculate and print the harmonic mean of the same numbers according to the following formula: 3. PT harmonic _mean-1 1 22x (Test with integer values of 4, 7, and 8. You may submit one program per...

  • Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first numbe...

    Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first number in the file will be an integer, and will indicate the amount of decimal numbers to follow. Once you have the read the numbers from the file into an array then compute the following properties on the set of numbers: the sum, the average (mean), the variance, the standard deviation, and the median. Don’t try to do the entire program...

  • C++ please Problem 3: Write a C++ program that prompts the user to enter an integer...

    C++ please Problem 3: Write a C++ program that prompts the user to enter an integer of any length (but not more than 8- digits), the program then extracts and prints each digit in its respective column. For example, in the integer 436, 4 should be printed in the 4th column, 3 in the 3rd and 6 in the 6th column. Hint: you can use setw to solve this problem. Sample Input/Output Enter an integer of any length. 9836472 ...Printing...

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