Hi the code is giving issues. Please help me fix. I have posted the code and project prompt. Thank you!!!!!! **PROMPT** Please write a C++ program that will accept 3 integer numbers from the user, and then output these 3 numbers in ascending order, their sum, and their average. You must stop your program when the first number from the user is -999. Program Design Specifications and Regulations:
Hi the code is giving issues. Please help me fix. I have posted the code and project prompt. Thank you!!!!!!
**PROMPT**
Please write a C++ program that will accept 3 integer numbers from the user, and then output these 3 numbers in ascending order, their sum, and their average. You must stop your program when the first number from the user is -999. Program Design Specifications and Regulations:
(1) You must use your full name on your welcome and thank-you messages.
(2) You must specify 3 prototypes in your program (before main( ) ) for 3 functions as follows: int max(int p, int q, int r); // prototype to return maximum of p, q, r int min(int p, int q, int r); // prototype to return minimum of p, q, r int mid(int p, int q, int r); // prototype to return middle of p, q, r
(3) You must define the above three integer functions properly in your program after main( ). If you define those three functions before main( ), you should not specify those 3 prototypes.
(4) You must NOT use any C++ existing or pre-defined functions in your program.
(5) You must fully test your program to make sure that these three functions are working perfectly for any 3 numbers in any sequence.
(6) How to show those 3 numbers (p, q, r) in ascending order without sorting them at all? The answer is that you show their minimum number, middle number, and maximum number.
(7) How to check and detect that q is the middle number among p, q, and r? The answer is that you need to consider two cases as follows:
if (q >= p && q <= r) return q ; // case 1: r, q , p i.e., r <= q <= p
if (q >= r && q <= p) return q ; // case 2: p, q, r i.e., p <= q <= r
**CODE**
#include <iostream>
using namespace std;
int min(int, int, int);
int mid(int, int, int);
int max(int, int, int);
int main()
{
int p, q, r;
int testCase = 0;
cout << "Welcome to the Number Game of Joe!" << endl;
while(true)
{
cout << ++testCase << " ========================= " << endl;
cout << "Please enter 3 integer numbers in any order (-999 to stop): ";
cin >> p >> q >> r;
if (p == -999 || q == -999 || r == -999)
{
cout << ++testCase << " ========================= " << endl;
cout << "Thank you for playing this Number Game of Joe!" << endl;
cout << ++testCase << " ========================= " << endl;
break;
}
int sum = p + q + r;
int average = sum/3;
cout << "You entered 3 numbers: " << p << " , "<< q << "," << r << endl;
cout << "These 3 numbers in order are: " << min(p, q, r) << ", " << mid(p, q, r) << mid(p, q, r) << ", " << max(p, q, r) << endl;
cout << "The sum is " << sum << " and the average is " << average << endl;
}
return 0;
int max(int p, int q, int r)
{
int max = 0;
if (p > q && p > r)
max = p;
else if (q > p && q > r)
max = q;
else
max = r;
return max;
}
int mid(int p, int q, int r)
{
int mid = 0;
if ((q >= p && q <= r) || (r <= q && q <= p)
mid = q;
else if ((q <= p && p <= r)) || (r <= p && p <= q))
mid = p;
else
mid = r;
return mid;
}
int min(int p, int q, int r)
{
int min = 0;
if (p < q && p < r)
min = p;
else if (q < p && q < r)
min = q;
else
min = r;
return min;
}
}
Step by step
Solved in 3 steps with 1 images