willis0924
willis0924

Reputation: 67

C++ Compile Error

I can't figure out why I am getting these errors when I try to compile. I've never encountered the 'expected _ before _ token' error, but I believe they're common (if not feel free to enlighten me).

pe4.cpp: In function 'int main()':
pe4.cpp:18: error: expected ')' before ';' token
pe4.cpp:18: error: expected ';' before ')' token
pe4.cpp:45: error: a function-definition is not allowed here before '{' token
pe4.cpp:51: error: a function-definition is not allowed here before '{' token
pe4.cpp:57: error: a function-definition is not allowed here before '{' token

#include <iostream>

using namespace std;

void printStar(int);
void printSpace(int);
void printNewLine();

int main()
{
    int side, i, j;

    if (i=0; i < 2; i++)
    {
        cout << "Enter side: " << endl;
        cin << side;

        if (side < 3 || side > 20)
        {
            cout << "Out of Bounds!!!"
            return 0;
        }

        printStar(side);
        printNewLine();

        {
            printStar(1);
            printSpace(side-2);
            printStar(1);
            printNewLine();
        }

        printStar(side);
        printNewLine();
    }

    void printStar(int a)
    {
        for (int j = 0; j < a; j++)
            cout << "*";
    }

    void printSpace(int a)
    {
        for (int j = 0; j < a; j++)
            cout << " ";
    }

    void printNewLine()
    {
        cout << endl;
    }
}

Upvotes: 1

Views: 2907

Answers (3)

Harry Steinhilber
Harry Steinhilber

Reputation: 5239

The closing } of the int main() method needs to go before void printStart(int a).

Also, you need a ; at the end of cout << "Out of Bound!!!"

Upvotes: 0

jwismar
jwismar

Reputation: 12268

You are defining your functions printStar(), etc, inside your main() definition. Move those functions outside of main()'s closing bracket.

Upvotes: 0

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272687

You have no ; at the end of the cout << "Out of Bounds!!!" line.

You have if (i=0; i < 2; i++); that should be for (i=0;....

You have cin << side; that should be cin >> side.

You have defined your function bodies inside main(); they should live outside.

Upvotes: 3

Related Questions