C++ Code Help.

Hey everyone, I just joined this forum. I'm just starting to learn C++ and I've gotten pretty far I guess. This code was created just to test some of my already learned C++ knowledge. It worked fine until I added this bit into it.

1
2
3
4
5
6
7
8
9
10
11
    if (result == "You fail, sucker");
    {
        if (first > 20);
        {
            cout << "Your number is too big" << endl;
        }
        else if (first < 20);
        {
            cout << "Your number is too small" << endl;
        }
    }


After I put that in I received multiple errors in the output(I'm using Code::Blocks). This is the output.

1
2
3
4
5
6
7
/Users/MyName/Scripts/C++Starter/TheBeginning/main.cpp||In function 'int main()':|
/Users/MyName/Scripts/C++Starter/TheBeginning/main.cpp|29|error: expected `}' before 'else'|
/Users/MyName/Scripts/C++Starter/TheBeginning/main.cpp|29|error: expected `}' before 'else'|
/Users/MyName/Scripts/C++Starter/TheBeginning/main.cpp|29|error: expected unqualified-id before 'else'|
/Users/MyName/Scripts/C++Starter/TheBeginning/main.cpp|30|error: expected unqualified-id before '{' token|
/Users/MyName/Scripts/C++Starter/TheBeginning/main.cpp|33|error: expected declaration before '}' token|
||=== Build finished: 5 errors, 0 warnings ===|


NOTE : Line 29 is..

else if (first < 20);


Here's the code.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

using namespace std;

int main()
{
    int first = 10;
    int second = 20;
    int ad;
    string name;
    string result;
    result = first == second ? "The numbers are equal" : "The numbers are not equal";
    cout << result << endl;
    cout << "First number : " << first << " Second number : " << second << endl;
    cout << "Your name is : ";
    cin >> name;
    cout << "Hello " << name << endl;
    cout << "Please add a number to the first number to make the both numbers equal : ";
    cin >> ad;
    first += ad;
    result = first == second ? "You win!" : "You fail, sucker";
    cout << result << endl;
    if (result == "You fail, sucker");
    {
        if (first > 20);
        {
            cout << "Your number is too big" << endl;
        }
        else if (first < 20);
        {
            cout << "Your number is too small" << endl;
        }
    }
    return 0;
}



Thanks for the help before-hand!
an if statement is composed by the keyword "if", followed by the condition between parentheses, followed by a command or a block of commands, there is no semicolon. So lines 23, 25 and 29 should be

 
if(/*...*/) // no semicolon here 
Thank you! I've been unable to find help for that all morning!
Topic archived. No new replies allowed.