expected ';' before "else"

i cant seem to find were the ';' goes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void checkT(char temp[])
{
    if (temp[0] != '[' && temp[0] != '{' && temp[0] != '(');
    {
       do
       {
          cout << "Invalid first value! Must start with (,[,{" << endl;
          cout << "Write your values: " << flush;
          cin >> temp;
       } while (temp[0] != '[' && temp[0] != '{' && temp[0] != '(');

    }
    else
    {
        cout << "Pushing...." << endl;
    }
}


any other info on helping me improve this function is welcomed.
closed account (1vRz3TCk)
if (temp[0] != '[' && temp[0] != '{' && temp[0] != '('); // remove the semicolon
when i remove the else if compiles fine
It's a typo: ';' after 'if' statement is excess. To improve this code:
1
2
3
4
5
6
7
8
9
10
void checkT(char str[])
{
	while(str[0] != '(' && str[0] != '[' && str[0] != '{')
	{
		cout << "Invalid first value! Must start with (,[,{" << endl
			<< "Write your values: " << flush;
		cin >> str;
	}
	cout << "Pushing...." << endl;
}

(I think "Plushing" should be written in any case after the string is checked)
success!!!
thank you!!
Last edited on
one more question

how can i have it check for and ending value of },] or )

without knowing how many characters will be typed
how can i have it check for and ending value of },] or )
1
2
3
int len = strlen(str);
if(len > 0 && str[len - 1] != ')' && str[len - 1] != ']' && str[len - 1] != '}')
    cout << "Bad ending." << endl;
Topic archived. No new replies allowed.