Coding a Simple Game. Please assist

I'm not sure why I"m getting a "previous if before else" error on line 57.

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
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

//Function Prototypes
int getRandomCouch ();
int getRandomBed();
int getRandomPocket ();

int main()
{//Declare Variables:

    int look = 0;
    int numPlaces =1;
    int totalBucks = 0;
    int randomCouch= getRandomCouch ();
    int randomBed= getRandomBed ();
    int randomPocket = getRandomPocket ();

//Game Intro:
    cout << "Hey! My name's Andrey. I want to go buy some donuts, but I don't have any money. At the grocery store, a box of donuts costs 13 bucks! So here's my situation: I’ve got a few places I can look for some cash. Under my bed, in the couch, and in my pocket. If I can find 13 bucks, we can behold the glory of  maple bars, strudels and even the jelly filled kind! Sigh. Please help me look. I’m hungry, and I’m sure you are too. I’ll share if you help me look." << endl;

//Look For Money
while (numPlaces <4)
   {cout << "Where should we look? Press:" << endl;
    cout << "1 to scrounge through the couch" << endl;
    cout << "2 to look under the bed" << endl;
    cout << "3 to look in my pockets" << endl;
    cin >> look;
    if (look == 1)
        {
            cout << "Awesome! We found " << randomCouch << " bucks!" << endl;
            numPlaces += 1;

        }
    else if (look == 2)
    {
        cout << "Awesome! We found " << randomBed << " bucks!" << endl;
        numPlaces += 1;
    }

    else if (look == 3)
    {
        cout << "Awesome! We found " << randomPocket << " bucks!" << endl;
        numPlaces += 1;
}} //endwhile

//Determine Win or Loss:
 cout << "Let's add it up!" << endl;
 totalBucks = randomCouch + randomBed + randomPocket;

        if (totalBucks >= 13);
            cout << "We found: " << totalBucks << " bucks."<< endl;
            cout << "Hooray! Let's get a sugar rush!" << endl;
        else;
            {cout << "We found: " << totalBucks << " bucks."<< endl;
             cout << "Dang it... looks like we have to starve." << endl;
             cout << "Let's look again?" << endl;}
return 0;
}
int getRandomCouch ()
{
    srand(time(0));
    int randomCouch = 1 + rand() % 7 + 1;
    return randomCouch;

}

int getRandomBed()
  {
    srand (time(0));
    int randomBed = 1 + rand() % 7 + 1;
    return randomBed;
}

int getRandomPocket ()
{
    srand (time(0));
    int randomPocket = 1 + rand () % 7 + 1;
    return randomPocket;}

No semicolons after your if or else statements, I recommend good old curly braces instead :)
^ What he said:
1
2
3
4
5
6
7
8
9
10
11
12
        
if (totalBucks >= 13) // delete semicolon, include brackets
{
cout << "We found: " << totalBucks << " bucks."<< endl;
cout << "Hooray! Let's get a sugar rush!" << endl;
}
else // delete semicolon
{
cout << "We found: " << totalBucks << " bucks."<< endl;
 cout << "Dang it... looks like we have to starve." << endl;
cout << "Let's look again?" << endl;
}
Last edited on
Topic archived. No new replies allowed.