469,602 Members | 1,794 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Game of craps giving class error

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::prompt_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::play()
{
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::play_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::play()
{
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::play()
{
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::prompt()
{
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;
}

Sep 22 '07 #1
3 1630
Hello,

The errors are pretty straight forward. The functions prompt_for_bet()
and get_bet() are defined in the Bankroll class and not in the Player
class. Thus you cannot access them with temp.prompt_for_bet(). If you use
temp.money.prompt_for_bet() it should work.

- Jensen
Sep 22 '07 #2
On Sep 22, 6:42 pm, Jensen Somers <use...@jsomers.bewrote:
Hello,

The errors are pretty straight forward. The functions prompt_for_bet()
and get_bet() are defined in the Bankroll class and not in the Player
class. Thus you cannot access them with temp.prompt_for_bet(). If you use
temp.money.prompt_for_bet() it should work.

- Jensen
OHHHHH!!!!1 Dats it !!!!! :) It just didnt strike me!!
temp.money.prompt_for_bet(), I thought it should work
neverthelesss... maybe i should consolidate my foundation in
classes ... thnk you very much ...

Sep 23 '07 #3
temp.money.prompt_for_bet() it should work.
I tried using temp.money.prompt_for_bet(), it didnt work.
Now it displayed another error instead of the previous one. It says
that money is not a memeber of player.

wat do i do?

Oct 1 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.