473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1816
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: BlackHawke | last post by:
Hello! This is my second post. Ppl really helped me with the first. I hope there are answers for this one as well I own a game company (www.aepoxgames.net) releasing the beta for our first...
1
by: lblock | last post by:
i have this code that plays the game of craps, but i need to be able to take how much they brought and how much they want to bet. show the number on the dice and tell them it they won or lose and...
10
by: sam_cit | last post by:
Hi Everyone, I'm working on developing a chess game and i decided to use c++ for its object oriented approach. I have a bass class unit and is inherited to distinct number of units (like king,...
2
by: mer000 | last post by:
Can you guys help me out? I'm trying to create a very simple game of craps but having some trouble. Below are the rules and requirements. Much appreciated! Given the following rules for the game...
2
by: fairie | last post by:
It seems my choices aren't working out as I'd like. So from the first area when I input choice number 3, it should send me to the fourth area, as per the {3, 3, 0} - but it stays at the first area. ...
1
by: Shark2026 | last post by:
Hi there I need to make a Craps game for my class. Here are the parameters for it. In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the...
18
by: Rhodge09 | last post by:
This is my script it works fine but it comes out on my webpage as just text how can i change this around and make it so if i like click a button a 2 different numbers come up almost like the 2 dice...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.