expected ';' before "else"

Nov 4, 2011 at 3:28pm
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.
Nov 4, 2011 at 3:33pm
closed account (1vRz3TCk)
if (temp[0] != '[' && temp[0] != '{' && temp[0] != '('); // remove the semicolon
Nov 4, 2011 at 3:36pm
when i remove the else if compiles fine
Nov 4, 2011 at 3:36pm
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)
Nov 4, 2011 at 4:18pm
success!!!
thank you!!
Last edited on Nov 4, 2011 at 4:19pm
Nov 4, 2011 at 4:26pm
one more question

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

without knowing how many characters will be typed
Nov 4, 2011 at 4:44pm
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.