'A' help me

(31) bet..

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
  #include <iostream>
#include <ctime>

int race (int a, int b, int c);
void race();
int hold (int b, int c);
void init ();

int money = 200;

int main ()
{
	using std::cout;
	using std::cin;
	int act;
	
	cout<< "W e l c o m e\n" << money << " piece(s) at hand\n";

	do
	{
		cout<< "The Race\n"
			"1) Bet on Ⅰ\n"
			"2) Bet on Ⅱ\n"
			"3) Bet on Ⅲ\n"
			"4) Spectate\n"
			"0) Depart\n"
			"\n[Enter]: ";
		cin>> act;
	} while ( act < 0 || act > 4);
	
	hold (act, bet);
	race (money, act, bet);
	
	return 0;
}

int hold (int b, int c)
{
	using std::cout;
	using std::cin;

	cout<< "Snail " << b << " it is\n"
		   "Now, what is your bet?\n[Enter]: ";
	cin>> c;
return c;
}

int race (int a, int b, int c)
{
	using std::cout;
	using std::rand;
	init ();
	int outcome = rand () % 3;

	cout<< "-Klutch-\nThey're full of energy, today!\n\n"
		<< outcome << " is our winner of today!\n";
	
	if (outcome == b)
	{
		cout<< "Here is your profit\n";
		return ::money += c;
	}
	else
	{
		cout<< "Oh..";
		return ::money -= c;
	}
}

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

void init ()
{
	using std::srand;
	using std::time;
	srand (unsigned int(time(0))); //unsigned不要on srand
}
Last edited on
what the problem is?
looool I couldn't compile again. I probably have a broken file '^'
(31)'s bet is unidentified
Please, show on which line you declared "bet" variable in main()
Last edited on
// Snail
#include <iostream>
#include <ctime>

int race (int a, int b, int c);
void race();
void init ();

int money = 200;
int act;

int main ()
{
using std::cout;
using std::cin;
int bet = 0;

cout<< "W e l c o m e\n" << money << " piece(s) at hand\n";

do
{
cout<< "The Race\n"
"1) Bet on Ⅰ\n"
"2) Bet on Ⅱ\n"
"3) Bet on Ⅲ\n"
"4) Spectate\n"
"0) Leave\n"
"\n[Enter]: ";
cin>> act;
} while ( act < 0 || act > 4);

if (act == 4)
void hold();
if (act == 0)
{cout<< "\nCome join us again.\n"; return 0;}

if (act == 4)
return 0;

cout<< "Snail " << act << " it is\n"
"Now, what is your bet?\n[Enter]: ";
cin>> bet;

race (money, act, bet);

if (act == 4)
void race();
cout<< money << "piece(s) left..\n";
return 0;
}

int race (int a, int b, int c)
{
using std::cout;
using std::rand;
init ();
int outcome = rand () % 3;

++outcome;

cout<< "-Klutch-\nThey're full of energy, today!\n\nSnail "
<< outcome << " is our winner!\n";

if (act == 4)
return 0;

if (outcome == b)
{
cout<< "Here is your profit\n";
money += c;
return money;
}
else
{
cout<< "Oh..\n\n";
money -= c;
return money;
}
}

void init ()
{
using std::srand;
using std::time;
srand (unsigned int(time(0))); //unsigned不要on srand
}
Ok, what the problem now?

//4.4 - The Snail Racing Game -Dirk Henkemans and Mark Lee

#include <iostream> #include <ctime>

//function declarations
int race(int, int); void race(void); int menu(void);

int placeBet(int); void init(void);

//variables

int money = 200;

//the main function
int main(void)

{
using std::cout;

init();

int userResponse;

cout << “Welcome to the snail races!!!\n”;

while(userResponse = menu())

{
switch(userResponse)
{
case 1:
case 2:
case 3:
::money +=
race(placeBet(userResponse), userResponse);
break;
case 4:

//the user did not bet
race();
break;
}
}

//displays the main menu and returns the user’s selection
int menu(void)
{
using std::cout;
using std::cin;
int userResponse;

cout << “You have “ << money << “ dollars.\n”;

do
{
cout << “Races Menu\n” << “1) Bet on snail 1\n”
<< “2) Bet on snail 2\n” << “3) Bet on snail 3\n”

<< “4) Just Watch\n” << “0) Leave the races\n”;

cin >> userResponse;
} while(userResponse < 0 && userResponse > 4);

return userResponse;
}

//decides how much a person will bet on the snail
int placeBet(int userResponse)
{
using std::cout;
using std::cin;
int betAmount;

cout << “Snail “ << userResponse
<< “ is a good choice!\n”;

cout << “How much would you like to bet on your snail “

<< userResponse << ”? ”;

cin >> betAmount;

return betAmount;
}

//if they are just watching the race
void race (void)
{
race(0, 0);
}

//if they are betting money
int race (int money, int userResponse)
{
using std::cout; using std::rand;

//stores the random number
int winner = rand() % 3 + 1;

cout << “And the snails are off\n”

<< “Look at them GO!!!\n”

<< “The winner is snail “ << winner << “\n”;

if(winner == userResponse)
{
cout << “You Win!\n”; return 2 * money;

cout << ”You lose “ << money << “ dollars.\n”; return -1 * money;}
}

//handles program initializations
void init(void)
{
using std::srand; using std::time; srand(time(0));
}
Last edited on
this is what the book confused me with..thank you for your attention lol
it's wrong and the
int placebet() function
confused me
Topic archived. No new replies allowed.