This is a simple game of craps that I wrote. It has a betting system and keeps track of how many times you won. I'm looking for some comments, opinions, criticisms anything is appreciated.
main.cpp:
CODE
#include <iostream>
#include <math.h>
#include <time.h>
#include <iomanip>
#include "dice.h"
using namespace std;
int main()
{
float bank = 100, bet;
int roll, ctr = 0, conf;
cout << setprecision(2) << fixed;
do
{
system("cls");
conf = menu(bank);
}while(conf > 2);
srand(time(NULL));
while(conf == 1)
{
bet = wager(bank);
die();
roll = dice();
if(roll == 7 || roll == 11)
{
firstWin(ctr, roll, bank, bet);
}
else if(roll == 2 || roll == 3 || roll == 12)
{
firstLose(roll, bank, bet);
}
else
{
reRoll(ctr, roll, bet, bank);
}
if(bank == 0)
{
cout << "\n\nYou are out of money. ";
break;
}
do
{
system("pause");
system("cls");
conf = menu(bank);
}while(conf > 2);
}
summary(ctr, bank);
system("PAUSE>nul");
return EXIT_SUCCESS;
}
dice.h:
CODE
#ifndef _DICE_H_
#define _DICE_H_
#include <iostream>
#include <math.h>
#include <time.h>
#include <iomanip>
using namespace std;
int die(void);
int dice(void);
void firstWin(int &, int, float &, float);
void firstLose(int, float &, float);
void reRoll(int &, int, float, float &);
int menu(float);
float wager(float);
void summary(int , float);
int die()
{
return(rand() % 6 + 1);
}
int dice()
{
return(die() + die());
}
void firstWin(int &ctr, int roll, float &bank, float bet)
{
cout << "\n\nYou rolled a " << roll << "!!!\n\nYOU WIN!!!\n\n\n";
bank = bank + bet;
++ctr;
}
void firstLose(int roll, float &bank, float bet)
{
cout << "\n\nYou rolled a " << roll << "!!!\n\nYOU LOSE!!!\n\n\n";
bank = bank - bet;
}
void reRoll(int &ctr, int roll, float bet, float &bank)
{
int points = roll;
int conf;
cout << "\n\nYou rolled a " << roll << "!!!";
cout << "\n\n\nEnter 1 to roll...";
cin >> conf;
cout << "\n___________________________________";
while(conf == 1)
{
roll = dice();
if(roll == points)
{
cout << "\n\nYou rolled a " << roll
<< "!!!\n\n\nYOU WIN!!!";
bank = bank + bet;
++ctr;
break;
}
else if(roll == 7)
{
cout << "\n\nYou rolled a " << roll
<< "!!!\n\n\nYOU LOSE!!!";
bank = bank - bet;
break;
}
else
{
cout << "\n\nYou rolled a " << roll <<"!!!";
}
cout << "\n\nEnter 1 to roll...";
cin >> conf;
cout << "__________________________________";
}
}
int menu(float bank)
{
int x;
cout << "\n\n_______________CRAPS________________\n\n"
<< "\n1. Roll"
<< "\n2. Quit"
<< "\n3. Rules of Craps"
<< "\n4. Check your balance"
<< "\n\nEnter your choice: ";
cin >> x;
switch(x)
{
case 1: return(x);
case 2: return(x);
case 3: cout << "\n\n\nOn Your first roll:\n\nIf you roll a 7 or"
<< " 11 you win.\nIf you roll a 2, 3 or 12 you lose.\n"
<< "If you roll anything else that becomes your points"
<< " and you roll again.\n\n"
<< "On all rolls after the first:\n\nIf you roll a 7 "
<< "you lose.\nIf you roll your points again you win."
<< "\nIf you roll anything else you roll again."
<< "\nHave fun and good luck!\n\n";
return(x);
case 4: cout << "\n\nYour balance is " <<bank <<".\n\n";
return(x);
break;
default: cout << "Invalid input, try again\n\n";
}
}
float wager(float bank)
{
float bet;
cout << "___________________________________"
<< "\n\nYour balance is " <<bank << ".\n\n";
do
{
cout << "How much would you like to bet? ";
cin >> bet;
if(bet > bank)
{
cout << "\n\nYou don't have enough money.\n\n";
continue;
}
else
{
return(bet);
}
}while(bet > bank);
}
void summary(int ctr, float bank)
{
if(ctr < 5)
cout << "\n\nNice try. You won " << ctr << " times and ended the game "
<< "with " <<bank << " dollars.";
else if(ctr < 10)
cout << "\n\nGood job! You won " <<ctr << " times and "
<< "ended the game with " <<bank << " dollars.";
else
cout << "\n\nYou have really good luck! \nYou won " <<ctr << " times and "
<< "ended the game with " <<bank << " dollars.";
}
#endif
Let me know what you guys think

. Thanks.