W
whitehatmiracle
SOS
When i comile this program, im getting 13 errors all saying
"prompt_for_bet and get_bet are not memebers of class Player"
Where am i going wrong? Can anyone plzz enlighten me?
Thnking u all in advance
// gamble with Craps
#include "include.h"
int die();
class Bankroll
{
public:
Bankroll(int);
void prompt_for_bet();
int get_bet() { return bet; }
int get_balance() const;
void add(int);
void subtract(int);
private:
int balance;
int bet;
};
Bankroll::Bankroll(int start) : balance(start) {}
int Bankroll::get_balance() const
{
return balance;
}
void Bankroll::add(int amt)
{
balance += amt;
}
void Bankroll::subtract(int amt)
{
balance -= amt;
}
void Bankroll:rompt_for_bet()
{
cout << "Enter you bet size? ";
cin >> bet;
while(bet < 1 || bet > get_balance())
{
cout << "Invalid bet!\n";
cin >> bet;
}
}
int die(){
int x = rand() % 10 + 2;
return x;
}
class Player
{
public:
Player(int m) : money(m), start(m) {}
~Player();
int get_balance() const { return money.get_balance(); }
void add(int m) { money.add(m); }
void sub(int m) { money.subtract(m); }
private:
Bankroll money;
int start;
};
Player::~Player()
{
int end = money.get_balance();
if(end > start)
cout << "You won $" << end - start << '\n';
else if(end < start)
cout << "You lost $" << start - end << '\n';
else
cout << "You broke even\n";
}
class Pass_line
{
public:
Pass_line(Player& temp)
: temp(temp) {}
void play();
private:
Player& temp;
void play_point(int);
void win_come_out();
void lose_come_out();
void win_point();
void lose_point();
};
void Pass_line:lay()
{
temp.prompt_for_bet();
int dice_total = die(); /////
cout<<"The dice total is: "<<dice_total<<"/n";
switch(dice_total)
{
case 7 :
case 11 : win_come_out(); break;
case 2 :
case 3 :
case 12 : lose_come_out(); break;
default : play_point(dice_total); break;
}
}
void Pass_line:lay_point(int the_point)
{
cout << " The point is " << the_point << " \n";
int dice_total;
do
{
dice_total = die();
cout<<"The dice total is: "<<dice_total<<"/n";
if(dice_total == the_point)
win_point();
if (dice_total == 7)
lose_point();
}
while ((dice_total != the_point) && (dice_total != 7));
}
void Pass_line::win_come_out()
{
cout << "You win on the come-out roll\n";
temp.add(temp.get_bet());
}
void Pass_line::lose_come_out()
{
cout << "You lose on the come-out roll\n";
temp.sub(temp.get_bet());
}
void Pass_line::win_point()
{
cout << "You win the point\n";
temp.add(temp.get_bet());
}
void Pass_line::lose_point()
{
cout << "You lose the point\n";
temp.sub(temp.get_bet());
}
class Field_bet
{
public:
Field_bet(Player& temp)
: temp(temp) {}
void play();
private:
Player& temp;
void win11();
void win2();
void win12();
void lose();
};
void Field_bet:lay()
{
temp.prompt_for_bet();
int dice_total = die();
cout<<"The dice total is: "<<dice_total<<"/n";
switch(dice_total)
{
case 3 :
case 4 :
case 9 :
case 10 :
case 11 : win11(); break;
case 2 : win2(); break;
case 12 : win12(); break;
default : lose(); break;
}
}
void Field_bet::win11()
{
cout << "You win the field bet -- even bet\n";
temp.add(temp.get_bet());
}
void Field_bet::win2()
{
cout << "You win the field bet -- double the bet\n";
temp.add(temp.get_bet() * 2);
}
void Field_bet::win12()
{
cout << "You win the field bet -- triple the bet\n";
temp.add(temp.get_bet() * 3);
}
void Field_bet::lose()
{
cout << "You lose the field bet\n";
temp.sub(temp.get_bet());
}
class Any_7
{
public:
Any_7(Player& temp)
: temp(temp) {}
void play();
private:
Player& temp;
void win();
void lose();
};
void Any_7:lay()
{
temp.prompt_for_bet();
int dice_total = die();
cout<<"The dice total is: "<<dice_total<<"/n";
switch(dice_total)
{
case 7 : win(); break;
default : lose(); break;
}
}
void Any_7::win()
{
cout << "You win Any 7 -- quadruple the bet\n";
temp.add(temp.get_bet() * 4);
}
void Any_7::lose()
{
cout << "You lose Any 7\n";
temp.sub(temp.get_bet());
}
class C_raps
{
public:
C_raps(int);
~C_raps();
void prompt();
private:
Player temp;
int menu();
Pass_line PL;
Field_bet FB;
Any_7 A7;
};
C_raps::C_raps(int money) : temp(money), PL(temp),
FB(temp), A7(temp)
{
cout << "Welcome to the game of C Raps!\n";
}
C_raps::~C_raps()
{
cout << "C Raps is self destructing\n";
}
int C_raps::menu()
{
cout << "\n========*****========\n";
cout << "You have " << temp.get_balance() << " in your account\n
\n";
cout << "(P)ass line\n";
cout << "(F)ield bet\n";
cout << "(A)ny 7\n";
cout << "(E)xit\n";
cout << "Your choice: ";
char choice;
cin >> choice;
return toupper(choice);
}
void C_raps:rompt()
{
char choice;
while((temp.get_balance() > 0) && ((choice = menu()) != 'E'))
switch(choice)
{
case 'P' : PL.play();
break;
case 'F' : FB.play();
break;
case 'A' : A7.play();
break;
default : cout << "Invalid choice of " << choice << '\n';
}
}
int main()
{
const int start = 100; //starting bank roll amount
C_raps game(start);
game.prompt();
getch();
return 0;
}
When i comile this program, im getting 13 errors all saying
"prompt_for_bet and get_bet are not memebers of class Player"
Where am i going wrong? Can anyone plzz enlighten me?
Thnking u all in advance
// gamble with Craps
#include "include.h"
int die();
class Bankroll
{
public:
Bankroll(int);
void prompt_for_bet();
int get_bet() { return bet; }
int get_balance() const;
void add(int);
void subtract(int);
private:
int balance;
int bet;
};
Bankroll::Bankroll(int start) : balance(start) {}
int Bankroll::get_balance() const
{
return balance;
}
void Bankroll::add(int amt)
{
balance += amt;
}
void Bankroll::subtract(int amt)
{
balance -= amt;
}
void Bankroll:rompt_for_bet()
{
cout << "Enter you bet size? ";
cin >> bet;
while(bet < 1 || bet > get_balance())
{
cout << "Invalid bet!\n";
cin >> bet;
}
}
int die(){
int x = rand() % 10 + 2;
return x;
}
class Player
{
public:
Player(int m) : money(m), start(m) {}
~Player();
int get_balance() const { return money.get_balance(); }
void add(int m) { money.add(m); }
void sub(int m) { money.subtract(m); }
private:
Bankroll money;
int start;
};
Player::~Player()
{
int end = money.get_balance();
if(end > start)
cout << "You won $" << end - start << '\n';
else if(end < start)
cout << "You lost $" << start - end << '\n';
else
cout << "You broke even\n";
}
class Pass_line
{
public:
Pass_line(Player& temp)
: temp(temp) {}
void play();
private:
Player& temp;
void play_point(int);
void win_come_out();
void lose_come_out();
void win_point();
void lose_point();
};
void Pass_line:lay()
{
temp.prompt_for_bet();
int dice_total = die(); /////
cout<<"The dice total is: "<<dice_total<<"/n";
switch(dice_total)
{
case 7 :
case 11 : win_come_out(); break;
case 2 :
case 3 :
case 12 : lose_come_out(); break;
default : play_point(dice_total); break;
}
}
void Pass_line:lay_point(int the_point)
{
cout << " The point is " << the_point << " \n";
int dice_total;
do
{
dice_total = die();
cout<<"The dice total is: "<<dice_total<<"/n";
if(dice_total == the_point)
win_point();
if (dice_total == 7)
lose_point();
}
while ((dice_total != the_point) && (dice_total != 7));
}
void Pass_line::win_come_out()
{
cout << "You win on the come-out roll\n";
temp.add(temp.get_bet());
}
void Pass_line::lose_come_out()
{
cout << "You lose on the come-out roll\n";
temp.sub(temp.get_bet());
}
void Pass_line::win_point()
{
cout << "You win the point\n";
temp.add(temp.get_bet());
}
void Pass_line::lose_point()
{
cout << "You lose the point\n";
temp.sub(temp.get_bet());
}
class Field_bet
{
public:
Field_bet(Player& temp)
: temp(temp) {}
void play();
private:
Player& temp;
void win11();
void win2();
void win12();
void lose();
};
void Field_bet:lay()
{
temp.prompt_for_bet();
int dice_total = die();
cout<<"The dice total is: "<<dice_total<<"/n";
switch(dice_total)
{
case 3 :
case 4 :
case 9 :
case 10 :
case 11 : win11(); break;
case 2 : win2(); break;
case 12 : win12(); break;
default : lose(); break;
}
}
void Field_bet::win11()
{
cout << "You win the field bet -- even bet\n";
temp.add(temp.get_bet());
}
void Field_bet::win2()
{
cout << "You win the field bet -- double the bet\n";
temp.add(temp.get_bet() * 2);
}
void Field_bet::win12()
{
cout << "You win the field bet -- triple the bet\n";
temp.add(temp.get_bet() * 3);
}
void Field_bet::lose()
{
cout << "You lose the field bet\n";
temp.sub(temp.get_bet());
}
class Any_7
{
public:
Any_7(Player& temp)
: temp(temp) {}
void play();
private:
Player& temp;
void win();
void lose();
};
void Any_7:lay()
{
temp.prompt_for_bet();
int dice_total = die();
cout<<"The dice total is: "<<dice_total<<"/n";
switch(dice_total)
{
case 7 : win(); break;
default : lose(); break;
}
}
void Any_7::win()
{
cout << "You win Any 7 -- quadruple the bet\n";
temp.add(temp.get_bet() * 4);
}
void Any_7::lose()
{
cout << "You lose Any 7\n";
temp.sub(temp.get_bet());
}
class C_raps
{
public:
C_raps(int);
~C_raps();
void prompt();
private:
Player temp;
int menu();
Pass_line PL;
Field_bet FB;
Any_7 A7;
};
C_raps::C_raps(int money) : temp(money), PL(temp),
FB(temp), A7(temp)
{
cout << "Welcome to the game of C Raps!\n";
}
C_raps::~C_raps()
{
cout << "C Raps is self destructing\n";
}
int C_raps::menu()
{
cout << "\n========*****========\n";
cout << "You have " << temp.get_balance() << " in your account\n
\n";
cout << "(P)ass line\n";
cout << "(F)ield bet\n";
cout << "(A)ny 7\n";
cout << "(E)xit\n";
cout << "Your choice: ";
char choice;
cin >> choice;
return toupper(choice);
}
void C_raps:rompt()
{
char choice;
while((temp.get_balance() > 0) && ((choice = menu()) != 'E'))
switch(choice)
{
case 'P' : PL.play();
break;
case 'F' : FB.play();
break;
case 'A' : A7.play();
break;
default : cout << "Invalid choice of " << choice << '\n';
}
}
int main()
{
const int start = 100; //starting bank roll amount
C_raps game(start);
game.prompt();
getch();
return 0;
}