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

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

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

  • Write a c++ complete program to meet the specifications. The program should prompt the user for...

    Write a c++ complete program to meet the specifications. The program should prompt the user for a positive integer. The program should print a message whether the integer is even or odd. The looping should end when the user enters a negative number. The negative number will not be tested for even or odd. The program will print out a message of how many numbers were entered (not counting the negative number) and how many even and odd numbers were...

  • Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices....

    Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices. 1. Find the number of digits in an integer. 2. Find the nth digit in an integer. 3. Find the sum of all digits of an integer. 4. Is the integer a palindrome? 5. Quit Enter a choice: Page 1 of 4 For each of the choices (1, 3, 4), Read a positive integer number and call a function that processes the menu choice...

  • 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 program that asks the user how many integers they would like to enter. You...

    Write a program that asks the user how many integers they would like to enter. You can assume they will enter an integer >= 1. The program will then prompt the user to enter that many integers. After all the numbers have been entered, the program should display the largest and smallest of those numbers (no, you cannot use lists, or any other material we haven't covered). When you run your program it should match the following format: How many...

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