I need to write a poker game that simulates a penalty kick in a soccer match. Three cards are drawn randomly.
void DrawCard(int& numberOne, int& numberTwo, int& numberThree)
{
RandNoGen(); //init random number generator
numberOne = rand() % 13 + 1; //random number in [1, 13]
do
{
numberTwo = rand() % 13 + 1;
numberThree = rand() % 13 + 1;
}
while (numberOne == numberTwo); //Their values randomly from 1 to 13, the first two values cannot be the same
while(true) //inner forever loop
{
cout << "\nThe two goalposts are " << numberOne << " and " << numberTwo << "\n";
//And act as the goalposts while the third value represents the third card
cout << "Press any key to kick action.\n";
cin >> key;
cout << "The third goalpost is " << numberThree << "\n";
if (numberOne < numberThree && numberThree < numberTwo || numberTwo < numberThree && numberThree < numberOne)
{
cout << "Goal!! You win $" << betMoney << ".\n";
break;
}
else if (numberThree == numberOne || numberThree == numberTwo)
{
cout << "Amazing... You hit the goalpost! You lose $" << moneyLostSame << ".\n";
break;
}
else
{
cout << "Oh! It's out, you lose $" << betMoney << ".\n";
break;
}
}
}
But instead of showing A, 2, ..., J, Q, K, it shows 1 to 13.
How can I convert 1, 11, 12, 13 back to A, J, Q, K?
Also, there's a Game Menu before starting the betting game.
char GameMenu()
{
cout << "\n=== Penalty kick game ===\n\n";
cout << "[r] The record of your game\n";
cout << "[s] Start betting\n";
cout << "[b] Back to the betting room\n";
cout << "Enter your choice (r, s or b) :";
cin >> secondChoice;
return secondChoice;
}
void ChoiceGameMenu()
{
while(true)
{
switch (GameMenu())
{
case 'r': cout << "\nNumber of times that you won: " << x << "\n";
cout << "Number of times that you lost: " << y << "\n";
break;
case 'R': cout << "\nNumber of times that you won: " << x << "\n";
cout << "Number of times that you lost: " << y << "\n";
break;
case 's': if (moneyInAccount < 100)
{
cout << "\nNo sufficient money to bet the game!\a\n";
continue;
}
else if (moneyInAccount >= 100)
{
cout << "\nPlease enter the amount of money to bet: $";
cin >> betMoney;
if (betMoney < 100)
{
cout << "\nA hundred dollars is minimum, please input again.\a\n";
}
else if (betMoney >= 100)
{
MoneyBet(moneyInAccount);
DrawCard(numberOne, numberTwo, numberThree);
}
}
case 'S': if (moneyInAccount < 100)
{
cout << "\nNo sufficient money to bet the game!\a\n";
}
else if (moneyInAccount >= 100)
{
cout << "\nPlease enter the amount of money to bet: $";
cin >> betMoney;
if (betMoney < 100)
{
cout << "\nA hundred dollars is minimum, please input again.\a\n";
}
else if (betMoney >= 100)
{
MoneyBet(moneyInAccount);
DrawCard(numberOne, numberTwo, numberThree);
}
}
case 'b': return; //Back to Welcome Menu
case 'B': return;
default: cout << "\nInvalid input, please enter again!\a\a";
return;
}
}
}
Can I make it simplier by combining small and capital letter into one option?
i.e. combining case 'b' and case 'B' together, just using one case.
I have a welcome menu before the game menu. After playing the betting game for one time, it should return to the Game Menu instead of Welcome Menu. What's wrong here?
Also, why does the betting game play for two consecutive times before return instead of one time only?