I'd say that in the function void getBet() you have to let the user type in an amount they want to bet (you can do this using cin) and thus set the variable int bet . You also need to let the user choose which side of the dice they want to bet on, which would be another variable.
The if-statement you have there at the moment doesn't make any sense, as you can do all this in the function void wonTheBet(). At the moment you also need to actually "roll the dice" and compare the value of the randomly chosen side to the one the user has his bet on. If its the same, call the function wonTheBet, if not call a function lostTheBet, which has the logic of your current else-statement.
I hope this helped you, if there are any more questions, feel free to ask ;).
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
bool won;
void getBet();
void throwingDice();
void result();
float bet;
int faceBet;
int faceThrown;
int money = 100;
int faces = 6;
int main()
{
while (money > 0) {
cout << "You currently have " << money << " dollars. \n";
getBet();
if (won == true)
{
int amount = bet * 2;
money += amount;
cout << "Congratulations! You just won " << amount << " dollars!\n\n";
}
else
{
money -= bet;
cout << "Ah, you lost! Try again! \n\n";
}
}
cout << "You are out of money!\n";
return 0;
}
void getBet()
{
cout << "Please input the face you want to place your bet on:\n";
cin >> faceBet;
while (faceBet > faces) //Just there so that the user can't input 10 or sth. like that
{
cout << "A dice has six faces, so please choose a number from 1 to 6!\n";
cin >> faceBet;
}
cout << "Please tell us how much you want to bet on that face (" << faceBet << "):\n";
cin >> bet;
while (bet > money) // checking whether the user wants to bet more than he has
{
cout << "You only have " << money << "$. Please bet an amount less than or equal to the money you have left.\n";
cin >> bet;
}
cout << "Your bet is " << bet << "$ on Nr. " << faceBet << ".\n";
throwingDice();
}
void throwingDice()
{
srand(time(NULL));
int randomInt = rand() % 70;
if (randomInt < 10)
{
faceThrown = 1;
}
if (randomInt > 9 && randomInt < 20)
{
faceThrown = 2;
}
if (randomInt > 19 && randomInt < 30)
{
faceThrown = 3;
}
if (randomInt > 29 && randomInt < 40)
{
faceThrown = 4;
}
if (randomInt > 39 && randomInt < 50)
{
faceThrown = 5;
}
if (randomInt > 49 && randomInt < 60)
{
faceThrown = 6;
}
result();
}
void result()
{
if (faceBet == faceThrown)
{
won = true;
}
else
{
won = false;
}
}