Having trouble with parse errors

Here's the code I have written. I keep getting parse errors and since I've started programming only a couple weeks ago I really don't quite understand what the error is for.


if (answer_16 == 'Y')
cout << "Is your number less than 2?" << endl;
char answer_32 = 0;
cin >> answer_32;
if (answer_32 == 'Y')
cout << "Is your number 1?" << endl;
char answer_64 = 0;
cin >> answer_64;
if (answer_64 == 'Y')
cout << "Told You" << endl;
else if (answer_64 == 'N')
cout << "You must of messed up somewhere..." << endl;
else
cout << "I hope you thought that was funny..." << endl;
else if (answer_32 == 'N')
cout << "Is your number 2?" << endl;
char answer_65 = 0;
cin >> answer_65;
if (answer_65 == 'Y')
cout << "Told You" << endl;
else if (answer_65 == 'N')
cout << "You must of messed up somewhere..." << endl;
else
cout << "I hope you thought that was funny..." << endl;
else
cout << "I hope you thought that was funny..." << endl;
Could you put it in [code][/code] tags with indentation? It's kind of hard to read as is.
int main()
{
cout << "Think of a whole number 1 through 100?" << endl
<< "Got it?" << endl
<< "Now I'm going to figure out what number you thought of in 7 questions." << endl
<< "Is your number less than 50? (Y for yes and N for no)" << endl;
char answer_1 = 0;
char answer_13 = 0;
cin >> answer_1;
if (answer_1 == 'Y')
cout << "Is your number less than 25?" << endl;
char answer_2 = 0;
cin >> answer_2;
if (answer_2 == 'Y')
cout << "Is your number less than 12?" << endl;
char answer_4 = 0;
cin >> answer_4;
if (answer_4 == 'Y')
cout << "Is your number less than 6?" << endl;
char answer_8 = 0;
cin >> answer_8;
if (answer_8 == 'Y')
cout << "Is your number less than 3?" << endl;
char answer_16 = 0;
cin >> answer_16;
if (answer_16 == 'Y')
cout << "Is your number less than 2?" << endl;
char answer_32 = 0;
cin >> answer_32;
if (answer_32 == 'Y')
cout << "Is your number 1?" << endl;
char answer_64 = 0;
cin >> answer_64;
if (answer_64 == 'Y')
cout << "Told You" << endl;
else if (answer_64 == 'N')
cout << "You must of messed up somewhere..." << endl;
else
cout << "I hope you thought that was funny..." << endl;
else if (answer_32 == 'N')
cout << "Is your number 2?" << endl;
char answer_65 = 0;
cin >> answer_65;
if (answer_65 == 'Y')
cout << "Told You" << endl;
else if (answer_65 == 'N')
cout << "You must of messed up somewhere..." << endl;
else
cout << "I hope you thought that was funny..." << endl;
else
cout << "I hope you thought that was funny..." << endl;

that's just the beginning of a 1000 line code that for some reason my dumb ass thought would compile. probably an epic fail but hey, that's how we learn.
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
int main()
{
    cout << "Think of a whole number 1 through 100?" << endl
        << "Got it?" << endl
        << "Now I'm going to figure out what number you thought of in 7 questions." << endl
        << "Is your number less than 50? (Y for yes and N for no)" << endl;
    char answer_1 = 0;
    char answer_13 = 0;
    cin >> answer_1;
    if (answer_1 == 'Y')
        cout << "Is your number less than 25?" << endl;
        char answer_2 = 0;
        cin >> answer_2;
        if (answer_2 == 'Y')
            cout << "Is your number less than 12?" << endl;
            char answer_4 = 0;
            cin >> answer_4;
            if (answer_4 == 'Y')
                cout << "Is your number less than 6?" << endl;
                char answer_8 = 0;
                cin >> answer_8;
                if (answer_8 == 'Y')
                    cout << "Is your number less than 3?" << endl;
                    char answer_16 = 0;
                    cin >> answer_16;
                    if (answer_16 == 'Y')
                        cout << "Is your number less than 2?" << endl;
                        char answer_32 = 0;
                        cin >> answer_32;
                        if (answer_32 == 'Y')
                            cout << "Is your number 1?" << endl;
                            char answer_64 = 0;
                            cin >> answer_64;
                            if (answer_64 == 'Y')
                                cout << "Told You" << endl;
                            else if (answer_64 == 'N')
                                cout << "You must of messed up somewhere..." << endl;
                            else
                                cout << "I hope you thought that was funny..." << endl;
else if (answer_32 == 'N')
                            cout << "Is your number 2?" << endl;
                            char answer_65 = 0;
                            cin >> answer_65;
                            if (answer_65 == 'Y')
                                cout << "Told You" << endl;
                            else if (answer_65 == 'N')
                                cout << "You must of messed up somewhere..." << endl;
                            else
                                cout << "I hope you thought that was funny..." << endl;
                        else
                            cout << "I hope you thought that was funny..." << endl;
                    else if (answer_16 == 'N')
                        cout << "Is your number less than 4?" << endl;
                        char answer_33 = 0;
                        cin >> answer_33;
                        if (answer_33 == 'Y')
                            cout << "Is your number 3?" << endl;
                            char answer_66 = 0;
                            cin >> answer_66;
                            if (answer_66 == 'Y')
                                cout << "Told You" << endl;
                            else if (answer_66 == 'N')
                                cout << "You must of messed up somewhere..." << endl;
                            else
                                cout << "I hope you thought that was funny..." << endl;
                        else if (answer_33 == 'N')
                            cout << "Is your number 4?" << endl;
                            char answer_67 = 0;
                            cin >> answer_67;
                            if (answer_67 == 'Y')
                                cout << "Told You" << endl;
                            else if (answer_67 == 'N')
                                cout << "Your number is 5, unless you messed up somewhere..." << endl;
                            else
                                cout << "I hope you thought that was funny..." << endl;
First, I'd make sure all your if statements are applying to the blocks you want. Normally, an if statement only applies to the single statement afterward unless you use { } to create a larger block.
1
2
3
4
5
6
7
8
9
if(stuff())
    foo();
bar(); // these aren't included
bar2();
if(stuff()) {
    foo();
    bar(); // now they are included
    bar2();
}
Last edited on
dude, I appreciate it. I had no idea why it wasn't working.
Topic archived. No new replies allowed.