Hi, I keep getting this error when i run the code. How can I fix it?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

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;
}
}

main.cpp: In function 'int main()':
main.cpp:45:5: error: a function-definition is not allowed here before {' token
{
main.cpp:60:5: error: a function-definition is not allowed here before {' token
{
main.cpp:74:5: error: a function-definition is not allowed here before {' token
{
Transcribed Image Text:main.cpp: In function 'int main()': main.cpp:45:5: error: a function-definition is not allowed here before {' token { main.cpp:60:5: error: a function-definition is not allowed here before {' token { main.cpp:74:5: error: a function-definition is not allowed here before {' token {
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education