Hi, I keep getting this error when i run the code. How can I fix it?
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Hi, I keep getting this error when i run the code. How can I fix it?
Here is the 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 2 steps with 2 images