Dice Game help

I have a really simple issue and I can't seem to get it.

My only issue is getting it to print out an error if they enter 0 for a bet, or executing the last few if statements in main, if they enter a negative number.

Here is what I have so far.


#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdlib>
#include<ctime>
using namespace std;

oid welcome();
void rolldice(int& , int& ); //use a pass through variable
//name all of the functions that will be used
bool checkwin(int , int);

int main()
{

int die1=0, die2=0;//create variables
const int start=500;
int balance=start;
int bet;

welcome();

//do/while for when the bet is positive and the balance is greater than 0
do{
cout <<"You have $" << balance <<" remaining \n";//let user know how much they start with
cout << "Place your bet: ";
cin >> bet; //let user place a bet

rolldice(die1, die2); //call function to simulate dice rolls
cout<<"You rolled "<<die1<<" and "<< die2<< " = "<< (die1+die2)<< endl;
if(checkwin(die1, die2)){
//return a boolean value to check if the sum is 7
balance = (balance+bet);
cout<< "You Win!!\n\n" ;}
else{
balance = (balance-bet);
cout<<"You Lose!!\n\n";}


}while((bet>0)&&(balance>0));
//Tells user whether they won/lost and how much they made
cout <<"Thanks for playing!";
if(balance >start)
cout<<" You won "<< (balance-start);
else if(balance <start)
cout<<" You lost " << (start-balance);
else
cout<<" You broke even!";
}

//function just to tell user about the game
void welcome()
{
cout <<"***** Welcome to SEVENS! The Betting dice game! *****";
cout <<'\n' << "Wager whatever you'd like. If you roll a 7, you " <<
"win whatever you bet!\n" <<"But beware, if you don't roll a 7, " <<
"you lose your wager\n" << "Enter a negative bet if you'd like to" <<
" quit the game early \n" << "LET's BEGIN!!! \n\n";

}

//function to change the die variables and to simulate dice rolls
void rolldice(int& die3 , int& die4)
{
srand((unsigned int)time(0));
die3 = rand() % 6 + 1;
die4 = rand() % 6 + 1;
}

//Returns a true if the sum of the rolls is 7/ false otherwise
bool checkwin(int die1,int die2)
{
bool check;
if((die1+die2)==7)
check=true;
else
check=false;

return(check);

}
Last edited on
Topic archived. No new replies allowed.