why won't this compile?

Hey guys, I am a beginner in C++ and I have a question on one of the programs I've been writing for some programming practice. it keeps on giving me an error that says: "A function definition is not allowed here before the '{' token." I don't understand this and I want some help so I can compile this please help. The problems are around the end where the area, surface area, and volume functions are. I put notes right by the errors, they are near the very bottom, thanks guys in advance.


#include <iostream>
#include <windows.h>
#include <cmath>

using namespace std;

void Multiplication();
void Division();
void Addition();
void Subtraction();
void Area();
void SurfaceArea();
void Volume();

int main()
{

cout << "Welcome to your very own Homework helper!(math edition)" << endl;
cout << "Choose the subject in math that you would like us to help you with." << endl;
cout << endl << endl;
system("pause");
int choice;
LOOP:
system("cls");
cout << "[1] Multiplication" << endl;
cout << "[2] Division" << endl;
cout << "[3] Addition" << endl;
cout << "[4] Subtraction" << endl;
cout << "[5] Area" << endl;
cout << "[6] Surface Area" << endl;
cout << "[7] Volume" << endl;
cout << "[8] Exit" << endl;

cin >> choice;

switch(choice)
{
case 1: Multiplication();
break;

case 2: Division();
break;

case 3: Addition();
break;

case 4: Subtraction();
break;

case 5: Area();
break;

case 6: SurfaceArea();
break;

case 7: Volume();
break;

case 8: return 0;
break;

default: cout << "Error* Type in the number next to the the subject in math in which you want help in." << endl;
break;
}
goto LOOP;
}

void Multiplication()
{
int a, b, product;
cout << "Enter in the fist number which you would like to multiply:" << endl;
cin >> a;
cout << "Now enter the next number:" << endl;
cin >> b;
product = a * b;
cout << "The product of these 2 numbers is: " << product << endl;
system("PAUSE");
}

void Division()
{
int a, b, quotient;
cout << "Enter in the fist number which you would like to divide:" << endl;
cin >> a;
cout << "Now enter the number which you would like to divide the first number by:" << endl;
cin >> b;
quotient = a / b;
cout << "The quotient of these 2 numbers is: " << quotient << endl;
cout << endl << endl;
cout << "As a reminder, this program will not find the remainder if it does in fact exsit" << endl;
system("PAUSE");
}

void Addition()
{
int a, b, c, sum;
string NumberChoice;
cout << "Enter in the fist number which you would like to add:" << endl;
cin >> a;
cout << "Now enter the next number:" << endl;
cin >> b;
cout << "Would you like to add another number or would you like to add the current numbers you have put in?" << endl;
cout << "[Y]es" << endl;
cout << "[N]o" << endl;
cin >> NumberChoice;

if(NumberChoice == "Y" || NumberChoice == "y")
{
cout << "Ok then, add your number here:" << endl;
cin >> c;
sum = a + b + c;
cout << "The sum of these numbers is: " << sum << endl;
}
if(NumberChoice == "N" || NumberChoice == "n")
{
sum = a + b;
cout << "Ok, the sum of these numbers is: " << sum << endl;
}

else
{
cout << "Please be sure to type correctly." << endl;
}


system("PAUSE");
}

void Subtraction()
{
int a, b, sum;
cout << "Enter in the number you would like to subtract from:" << endl;
cin >> a;
cout << "Now enter the number which you would like to subtract the first number by:" << endl;
cin >> b;
sum = a - b;
cout << "The sum of these 2 numbers is: " << sum << endl;
system("PAUSE");
}

void Area()
{
int a, b, area;
string ShapeChoice;
string ShapeChoice2;

cout << "Enter in the value of the first length:" << endl;
cin >> a;
cout << "Enter in the value of the hieght here:" << endl;
cin >> b;
area = a * b;
cout << "Is this shape a traingle?" << endl;
cout << "[Y]es" << endl;
cout << "[N]o" << endl;
cin >> ShapeChoice;

if(ShapeChoice == "y" || ShapeChoice == "Y")
{
area = a * b / 2;
cout << "The area of this object is : " << area << endl;
}

if(ShapeChoice == "n" || ShapeChoice == "N")
{
area = a * b;
cout << "The area of this object is : " << area << endl;
cout << endl << endl;
cout << "This is of course implying that your shape is eiteher a sqaure or rectangle." << endl;
}
else
{
cout << "Error please put in valid information." << endl;
}
system("PAUSE");
system("cls");
cout << "If the traingle, the square, and the rectangle aren't your shapes, is it a trapaziod?" << endl;
cout << "[Y]es" << endl;
cout << "[N]o" << endl;
cin >> ShapeChoice2;

if(ShapeChoice == "y" || ShapeChoice == "Y")
{
cout << "I'm sorry then I cannot perform the area. The forula for find the area of a trapiziod is simple: " << endl;
cout << "divide base 1 + base 2 and multiply that number by the hieght.";
cout << "1/2(b1 + b2)h" << endl;
}

if(ShapeChoice == "n" || ShapeChoice == "N")
{
cout << "Ok, alright well here are all of the formulas for area: " << endl;
cout << "Traingle = 1/2bh" << endl;
cout << "Rectangle or parallelogram = bs" << endl;
cout << "Circle = pi-r-sqaured: pi = 3.14" << endl;
cout << endl << endl;
system("PAUSE");
}

void SurfaceArea()
{//ERROR HERE
cout << "Program not yet developed." << endl;
system("PAUSE");
}

void Volume()
{//ERROR HERE
cout << "Program not yet developed." << endl;
system("PAUSE");
}//ERROR HERE
Last edited on
First, as a beginner in c++, never use goto.

Second, use code tags. http://www.cplusplus.com/articles/z13hAqkS/

You are missing the closing brace for Area, so you are still in the body of Area when you try to define SurfaceArea. Properly using indentation should keep this from happening.
When I tried to compile your code, the first error that I get is:

1>Snippets.cpp(105): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)


This means you forgot to #include <string>

That got rid of most of the errors. After compiling we now get:
1>Snippets.cpp(200): error C2601: 'SurfaceArea' : local function definitions are illegal
1>          Snippets.cpp(143): this line contains a '{' which has not yet been matched
1>Snippets.cpp(206): error C2601: 'Volume' : local function definitions are illegal
1>          Snippets.cpp(143): this line contains a '{' which has not yet been matched
1>Snippets.cpp(210): fatal error C1075: end of file found before the left brace '{' at 'Snippets.cpp(143)' was matched


This means that you are missing a } somewhere. I took a look at it is at the end of the Area function (before SurfaceArea()).

I can now compile your code by making these changes.
Thanks guys, this helped me a ton! I can't believe I forgot the closing brace....such a fail.
Topic archived. No new replies allowed.