Why does it say no previous if

if (input == "yes");
{
cout<<"I know how you feel";
cin.get();
}
else if (input == "no");
{
cout<<"Test";
cin.get();
cin.get();
}
You have an extra semicolon after each of your ifs.

This is what your code does right now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (input == "yes")
    ; // Empty statement that does nothing

{ // These curly braces don't really do anything in this case
    // These lines will always run (they're not part of the 'if')
    cout<<"I know how you feel";
    cin.get();
}

else if (input == "no") // Compiler error: no matching 'if'
    ;

{ // Some more curly braces that don't do anything
    cout<<"Test";
    cin.get();
    cin.get();
}
It stills says else without a previous if? and i copy pasted.
What, you copy-pasted the code I had above?
That's the exact same code -- I just reformatted it to show you why it's not compiling.

Take your original code and get rid of the semicolons after each of the ifs and it should compile.
closed account (EwCjE3v7)
Try this:

1
2
3
4
5
6
7
8
9
if (input == "yes") {
    cout<<"I know how you feel";
    cin.get();
}
else if (input == "no") {
    cout<<"Test";
    cin.get();
    cin.get();
}
Topic archived. No new replies allowed.