"expected unqualfied-id before 'if'" Error Assistance

I am getting the error "expected unqualfied-id before 'if'" on lines 49 and 54. I tried to fix it but I got stuck. Anyone know the cause of the problem?

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 #include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <dos.h>
using namespace std;

int main()
{
    int gWeapon;
    int Points = 0;
    int YN;
    retry:
    system("cls");
    std::cout << "Welcome to Econaball! Created by Matthew Pollard" << endl;
    std::cout << "You have " << Points << " Points!" << endl;
    srand( time(0));
    std::cout << "Please choose the cup you would like to shoot for! " << endl;
    std::cin >> YN;



    if (YN == 1)
    {

        std::cout << "Throwing... ";
        Sleep(400);
        gWeapon=rand()%100+1;
        if(gWeapon > 0 && gWeapon < 50)
        {
           std::cout << "Congratulations, you made it!" << endl;
           std::cout << "You've gained 10 points!";
           system("pause");
           goto retry;
        }
    }
        else if(gWeapon > 51 && gWeapon < 100)
        {
            std::cout << "You missed, sorry!" << endl;
            std::cout << "Better luck next time!" << endl;
        }

    }

    if (YN == 2)
    {
        std::cout << "Throwing... ";
        gWeapon=rand()%100+1;
    }
    if (YN == 3)
    {
        std::cout << "Throwing... ";
        gWeapon=rand()%100+1;
    }
}
That code is outside main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        else if(gWeapon > 51 && gWeapon < 100)
        {
            std::cout << "You missed, sorry!" << endl;
            std::cout << "Better luck next time!" << endl;
        }

    } //This brace is the closing brace for main

    if (YN == 2)
    {
        std::cout << "Throwing... ";
        gWeapon=rand()%100+1;
    }
    if (YN == 3)
    {
        std::cout << "Throwing... ";
        gWeapon=rand()%100+1;
    }


Remove the extra closing brace form right before if (YN == 2)

And I don't think those block is going to do what you want it to
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    if (YN == 1)
    {

        std::cout << "Throwing... ";
        Sleep(400);
        gWeapon=rand()%100+1;
        if(gWeapon > 0 && gWeapon < 50)
        {
           std::cout << "Congratulations, you made it!" << endl;
           std::cout << "You've gained 10 points!";
           system("pause");
           goto retry;
        }
    }  //This brace just closed the if (YN == 1) block
        else if(gWeapon > 51 && gWeapon < 100)
        {
            std::cout << "You missed, sorry!" << endl;
            std::cout << "Better luck next time!" << endl;
        }

That else if isn't being associated with if (gWeapon > 0 && gWeapon < 50), it'll be associated with if (YN == 1)
Unless that's what you intended, then disregard that, but your indentation suggests you wanted it to be associated with if(gWeapon > 0 && gWeapon < 50)
Programming is hard :( Thanks for the assistance, fixed it right up. I'm kind of new so I don't always see very simple mistakes like that.
Topic archived. No new replies allowed.