Compiling error... a function-definition is not allowed here before â{â token
I keep getting this compiling error
a function-definition is not allowed here before â{â token
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
double areaOfCircle (int r);
double lbsToKgs (int lbs);
double mphToFps (int mph);
int coinFlip (void);
int rollDi (void);
int main(void)
{
int done = 0;
char choice;
while ( !done )
{
cout << "Menu"
"[1] Area of Circle"
"[2] Convert lbs to kgs"
"[3] Convert mph to fps"
"[4] Coin flip"
"[5] Roll dice"
"Enter choice (q to quit)? ";
cin >> choice;
switch(choice)
{
case '1':
{
int r;
cout << "Enter positive int radius? ";
cin >> r;
double areaOfCircle (int r)
{
double pi = 3.14159;
double a;
a = pi * r * r;
return a;
}
cout << areaOfCircle(r) << "units squared" << endl;
break;
}
case '2':
{
int lbs;
cout<<"Enter positive int lbs? ";
cin>>lbs;
double lbsToKgs (int lbs)
{
double b;
b = lbs * 0 .45359237;
return b;
}
cout << lbsToKgs(lbs) << "kgs" << endl;
break;
}
case '3':
{
int mph;
cout << "Enter pos int mph? ";
cin >> mph;
double mphToFps (int mph)
{
double c;
c = mph * 1.46666667;
return c;
}
cout << mphToFps (mph) << "fps" << endl;
break;
}
case '4':
{
int coinFlip (void)
{
int f;
f = lrand48() % 2;
if (f ==1)
{
cout << "Heads" <<endl;
}
else
{
cout << "Tails" <<endl;
}
return f;
}
break;
}
case '5':
{
int rollDi (void)
{
int s, t;
s = (lrand48() % 6) + 1;
t = (lrand48() % 6) + 1;
if(s==1 && t==1)
{
cout << "Snake eyes!" << endl;
}
else
{
cout << s << " " << t << endl;
}
return s,t;
}
break;
}
case 'q':
{
done = 1;
break;
}
default:
cout<< "Invalid Choice try again";
}
}
return 0;
}
This is the output:
p7.cc: In function âint main()â:
p7.cc:39: error: a function-definition is not allowed here before â{â token
p7.cc:54: error: a function-definition is not allowed here before â{â token
p7.cc:69: error: a function-definition is not allowed here before â{â token
p7.cc:80: error: a function-definition is not allowed here before â{â token
p7.cc:124: error: expected `}' at end of input
p7.cc:124: error: expected `}' at end of input
p7.cc:124: error: expected `}' at end of input
p7.cc:124: error: expected `}' at end of input
I am really confused why these errors are there. Any help would be great.