Horse Betting Game (error c2059 syntax error >)

Hi I'm writing a very simple horse betting game but I keep getting a syntax error at line 54 and I do not know why. In the tutorial it works fine, have I missed something out? Or am I doing something wrong? Cheers!

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <Windows.h>
#include <ctime>

using namespace std;

int main(void);
int race(int, int);
void race(void);
int menu(void);
int placeBets(int);

int money = 100;

int main()
{
	srand(0);
	
	int userInput;
	cout << "Welcome to the races.\n";
	while (userInput = menu())
	{
		switch (userInput)
		{
		case 1:
		case 2:
		case 3:
				::money += race(placeBets(userInput), userInput);
				break;
		case 4:
		race();
		break;
	}

}

}
int menu(void)
{
	int userInput;
	cout << "You currently have $" << money << ".\n";

	do
	{
		cout << "Racing Menu\n";
		cout << "***********\n";
		cout << "1) Bet on first horse\n";
		cout << "2) Bet on second horse \n";
		cout << "3) Bet on third horse\n";
		cout << "4) Watch don't bet\n";
		cout << "0) Leave\n";
		cin >> userInput;
		}	
		while (userInput < 0 && > 3);
		return userInput;

}


int placeBets(int userInput)
{
	int placeBets;
	cout << "\n You're betting on horse " << userInput << "\n";
	cout << "How much would you like to bet on " << userInput;
	cout << "$";
	cin >> placeBets;
	return placeBets;

	if(money < 100)
{
	"You cannot bet that amount!\n";
}

}


void race(void)
{
	race(0, 0);
}

int race(int money, int userInput)
{
	int racewinner = rand() % 3;
	cout << "The horses are racing...\n";
	Sleep(3000);
	system("CLS");
	cout << "Horse " << racewinner << " won!\n";
	Sleep(2000);
	if(racewinner = userInput)
	{
		cout << "You're horse won!\n";
		cout << "You doubled your $!\n";
		return 2 * money;
	}

	else
	{
		cout << "\n Unfortunatly you bet on " << userInput << " but horse " << racewinner << " won.\n";
		cout << "\n You lost $ " << money;
		system("CLS");
		return -1 * money;
	}


}

Last edited on
On either side of the && you need to have a full statement. That means that the right-hand-side of the condition on line 54 is similar to while (> 3);.

Change line 54 to:
while (userInput < 0 && userInput > 3);
Oh of course I must've been blind! Thank you for quick responce and help :)
On line 80 to 84 I made it so it doesn't allow anyone to bet more than they have. It works except it takes away $1. Maybe the return -1? I can't think of another way...
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <Windows.h>
#include <ctime>

using namespace std;

int main(void);
int race(int, int);
void race(void);
int menu(void);
int placeBets(int);

int money = 100;

int main()
{
	srand(0);
	
	int userInput;
	cout << "Welcome to the races.\n";
	while (userInput = menu())
	{
		switch (userInput)
		{
		case 1:
		case 2:
		case 3:
				::money += race(placeBets(userInput), userInput);
				break;
		case 4:
		race();
		break;
	}

}

}
int menu(void)
{
	int userInput;
	cout << "You currently have $" << money << ".\n";

	do
	{
		cout << "Racing Menu\n";
		cout << "***********\n";
		cout << "1) Bet on first horse\n";
		cout << "2) Bet on second horse \n";
		cout << "3) Bet on third horse\n";
		cout << "4) Watch don't bet\n";
		cout << "0) Leave\n";
		cin >> userInput;
		}	
		while (userInput < 0 && userInput > 3);
		return userInput;

}


int placeBets(int userInput)
{
	int placeBets;
	cout << "\nYou're betting on horse " << userInput << "\n";
	cout << "How much would you like to bet on " << userInput;
	cout << "\n$";
	cin >> placeBets;
	return placeBets;

	
}


void race(void)
{
	race(0, 0);
}

int race(int money, int userInput)
{
	if( userInput <= money) // If bet more than you have, returns to betting menu
	{
		cout << "You cannot bet more than you have, please try again\n";
		return -1;
	}

	int racewinner = rand() % 3;
	cout << "The horses are racing...\n";
	Sleep(3000);
	system("CLS");
	cout << "Horse " << racewinner << " won!\n";
	Sleep(2000);
	if(racewinner = userInput)
	{
		cout << "You're horse won!\n";
		cout << "You doubled your $!\n";
		return 2 * money;
	}

	else
	{
		cout << "\n Unfortunatly you bet on " << userInput << " but horse " << racewinner << " won.\n";
		cout << "\n You lost $ " << money;
		system("CLS");
		return -1 * money;
	}


}


Never mind
int main();
return 0;

Worked a treat :)
Last edited on
Topic archived. No new replies allowed.