Can't figure out why I have the error...The error is: C2181: illegal else without matching if....My program is:

#include <iostream>
using namespace std;

int main()
{
    int x=300; //this is the room capacity
    int y=0; //number of people
    int z=0; //this is the equation answer
    int m=0; //this is the number to be calculated

    cout << "Please enter the number of people who will be attending the meeting. \n" << endl;
    cin >> y;

    if (y <= x)
        cout << "This is a legal number of people to attend the meeting. \n" << endl;

    else
        cout << "The meeting cannot be held as planned due to fire regulations. \n" << endl;


    if (y <= x)
        z = x - y;
        cout << "There is enough room at the meeting for " << z << " more people too attend.\n" << endl;

    else
        cout << "In order to have the meeting " << y - x << " people need to leave the room.\n" << endl;

    return 0;

}

Put a brace here.

if (y <= x)
{
z = x - y;
cout << "There is enough room at the meeting for " << z << " more people too attend.\n" << endl;
}
else
{
cout << "In order to have the meeting " << y - x << " people need to leave the room.\n" << endl;
}

It is good programming practice if you use braces for all the if else statements. Even if they have only one statement after the condition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.