I'm doing a project of a crown and anchor game where you basically bet on a side of a dice and if you guess correctly you win or vice versa. I've done most of the program except I just need a few thing I don't know how to do. I was restricted to only using one int variable for a dice, but I have to throw 3 instead of one.
My program is as follow:
#include<iostream>
#include<cstdlib>
#include<time.h>
#include<string>
usingnamespace std;
int getRandomNum(int lowRange, int highRange);
int main()
{
int totalMoney; // The amount of $ you have.
int money; // Amount of $ you'll bet.
int rollChoice; // Choice of your roll.
int diceRoll; // Actual dice roll.
srand( static_cast<int>( time(NULL) ) );
cout << "Welcome to the Crown and Anchor Game!" << endl;
cout << "Good Luck!!!!!" << endl;
cout << "How much money will you play with? $";
cin >> totalMoney;
cout << endl;
cout << "***************************************... << endl << endl;
cout << "Enter your bet $";
cin >> money;
while (money > totalMoney)
{
cout << "Please bet $" << totalMoney << " or lower." << endl;
cout << "Enter your bet $";
cin >> money;
}
cout << "Choose a character. Enter: " << endl;
cout << " 1 for Heart" << endl;
cout << " 2 for Crown" << endl;
cout << " 3 for Diamond" << endl;
cout << " 4 for Club" << endl;
cout << " 5 for Anchor" << endl;
cout << " 6 for Spade" << endl;
cout << "...Your Choice: ";
cin >> rollChoice;
while (!(rollChoice < 7 && rollChoice > 0))
{
cout << endl;
cout << "Please enter a valid character...." << endl << endl;
cout << "...Your Choice: ";
cin >> rollChoice;
}
cout << endl;
diceRoll = getRandomNum(1, 6);
cout << "Dice rolled: ";
switch (diceRoll)
{
case 1:
{
cout << "Heart";
break;
}
case 2:
{
cout << "Crown";
break;
}
case 3:
{
cout << "Diamond";
break;
}
case 4:
{
cout << "Club";
break;
}
case 5:
{
cout << "Anchor";
break;
}
default:
{
cout << "Spade";
break;
}
}
cout << endl << endl;
if (rollChoice == diceRoll)
{
cout << "You won $" << money*2 << endl;
cout << "Your current balance is $" << totalMoney + money*2 << endl;
}
else
{
cout << "You lost $" << money << endl;
cout << "Your current balance is $" << totalMoney - money << endl;
}
}
int getRandomNum(int lowRange, int highRange)
{
int randNum;
randNum = ( rand() % (highRange - lowRange + 1) ) + lowRange;
return randNum;
}
Right now I only have the game set up to roll 1 die, but how would I do it to allow 3 dices to roll without having 3 int variables for dice rolls? Also, I need to include whether the user wants to quit the game or not and if the user loses all his money, he loses the game.
Any help is appreciated, thanks.
Notice, I don't know if I did the math right when winning or losing money. Sorry. Also, I don't know if I'm missing some things.
The thing is that I don't know how to include the rolling three times dice. How and where do I write the code down? I'm confused in that aspect. The same goes with ending the game or keep the loop going if the player chooses to keep playing.