Question: I need help with a card game I am creating on C++. A player is asked to place a bet then they are drawn two
I need help with a card game I am creating on C++. A player is asked to place a bet then they are drawn two cards. They they are asked how much they want to bet that the next card will be in between the two cards they were dealt. They win their bet money if the third card is in between, if not they lose it. I am having trouble with three things. The first is that the first two cards are always the same, for example, it says they are dealt "two of clubs and two of clubs". The second problem I've run into is how much money the player has one they won/lost their bet and using that amount to state how much they have in the next round. The third thing I need help with is ending the game once the player has $0 or 10 times the amount of the original bet. Below is what I have. Thank you!!
#include
#include
#include
#include
#include
using namespace std;
class card
{
public:
card();
int get_rank();
string get_suit_string();
string get_rank_string();
private:
int rank;
int suit;
};
card::card() // default constructor
{
int a= 1;
int b=4;
int c=2;
int d=13;
srand ( (int)time (0));
int x= a+ rand()%(b-a+1);
int y= c+ rand()% (d-c+1);
suit=x;
rank= y;
}
int card:: get_rank()
{
return rank;
}
string card:: get_rank_string()
{
string r;
if (rank==2)
{
r= "Two";
}
if (rank==3)
{
r= "Three";
}
if (rank==4)
{
r= "Four";
}
if (rank==5)
{
r= "Five";
}
if (rank==6)
{
r= "Six";
}
if (rank==7)
{
r= "Seven";
}
if (rank==8)
{
r= "Eight";
}
if (rank==9)
{
r= "Nine";
}
if (rank==10)
{
r= "Ten";
}
if (rank==11)
{
r= "Jack";
}
if (rank==12)
{
r= "Queen";
}
if (rank==13)
{
r= "King";
}
if (rank==14)
{
r= "Ace";
}
return r;
}
string card:: get_suit_string()
{
string r;
if (suit== 1)
{
r= "Clubs";
}
if (suit== 2)
{
r= "Diamonds";
}
if (suit== 3)
{
r= "Hearts";
}
if (suit== 4)
{
r= "Spades";
}
return r;
}
int main()
{
card one, two;
cout<< "What is your name? ";
string name;
getline(cin,name);
double begin_money;
cout<< "How much money would you like to start with? ";
cin>> begin_money;
cout<< name << ", you have $" << begin_money<< "."<< endl;
int total;
while ((total >= 0) && (total<10*begin_money))
{
cout<< "You got a "<< one.get_rank_string() << " of "<< one.get_suit_string() << " and a "
<< two.get_rank_string()<< " of " << two.get_suit_string()<< "." << endl;
// outputs first round of two given cards
cout<< "How much do you want to bet the next card is in between? ";
int bet;
cin>> bet;
card three;
cout<< "You draw a " << three.get_rank_string()<< " of " << three.get_suit_string()<< ". "<< endl;
if ((three.get_rank() > one.get_rank() && three.get_rank() < two.get_rank())
|| (three.get_rank() < one.get_rank() && three.get_rank() > two.get_rank()))
{
cout << "YES! " << name << " you win $" << bet << endl;
total = begin_money+ bet;
}
else
{
cout << "TOO BAD! " << name << " you lose $" << bet << endl;
total= begin_money - bet;
cout<< endl << name<< ", you have $"<< total << "."<< endl;
}
if (total==begin_money*10)
{
cout<< name<< " ,you won!!!";
}
if (total==0)
{
cout<< name << ", you lost.";
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
