Iwan Cole
Iwan Cole

Reputation: 21

c++ syntax error help needed, missing ';' before '}'

else if((RI >= 181) && (RI <= 210)){
        if((ICT1 = false) || ((ICT2 = false) || (ICT3 = false))){
        cout << "ICT \n";
        if(ICT1 = false){
            ICT1 = true;
            goto endICT;
        }
        if(ICT2 = false){
            ICT2 = true;
            goto endICT;
        }
        if(ICT3 = false){
            ICT3 = true;
            goto endICT;
        }
            endICT:
    }

Hi there! This is just part of my program, and this bit of code appears a few times, with different variables and other stuff. When I compile the code, I get "error C2143: Syntax Error : missing ';' before '}'" I'm new to all this coding, and would appreciate any help! Thanks for your time! EDIT: Sorry, I didn't include enough of the code before! Basically a random number is chosen, and if it's within a range, it goes through this part. This range can only be chosen 3 times, because then the first 'if' would not be true. Thanks for all your help so far! Also the error is in the 'endICT:' line.

Upvotes: 2

Views: 660

Answers (4)

Happy Green Kid Naps
Happy Green Kid Naps

Reputation: 1673

This is semantically equivalent to your posted code:

else if ( RI >= 181 && RI <= 210 )
{
    cout << "ICT \n";
    if ( ! ICT1 )
        ICT1 = true;
    else if ( ! ICT2 )
        ICT2 = true;
    else if ( ! ICT3 )
        ICT3 = true;
}

Upvotes: 0

Kupto
Kupto

Reputation: 2992

First of all note that it is considered to be a bad practice to use goto statement. It should only be used if there is no other option.

There are few more things to this code. I have commented some into the code

if(ICT3 = false) //this will assign value false into variable ICT3
     //you might want to write if(ICT3 == false) to compare and execute
{
   ICT3 = true;
   goto endICT; //this goto statement is completely redundant
}

//I assume that you want to have some code here, that does not execute
//if ICT3 == false in the first place... You should use if() ... else
//statement instead

endICT: ; //You are missing some ; here should be enough
}

for more information on flow control statements in C/C++ go here. For more info about operators in C/C++ try this.

Upvotes: 4

aguyngueran
aguyngueran

Reputation: 1321

Probably the compiler is confused with your label endICT:

which is followed by closing )

Upvotes: 0

BlackBear
BlackBear

Reputation: 22979

Simply insert an empty statement:

                   if(ICT3 = false){
        ICT3 = true;
        goto endICT;
    }
        endICT: ;
}

Upvotes: 4

Related Questions