Greetings,
Don't mix C++ standard headers with the non-standard/deprecated headers. "iostream.h" is deprecated, the standard header is "iostream", and please do use the code tags, it makes it much easier for everybody to read your code thus makes it easier to provide help.
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Craps
{
private:
int sum, myPoint, die1, die2, workSum;
double bet, bettotal;
char playagain;
public:
int rollDice(); // function prototype
void internalGame();
};
//------------------------------------------------------------------------------
int Craps::rollDice()
{
die1 = 1 + rand() % 6;
die2 = 1 + rand() % 6;
workSum = die1 + die2;
cout << "Player rolled " << die1 << " + " << die2
<< " = " << workSum << endl;
return workSum;
}
//------------------------------------------------------------------------------
void Craps::internalGame()
{
do
{
cout <<"\a--------\a--------------------\a--------------\a" << endl;
cout <<"Enter the amount you have available to play: ";
cin >> bettotal;
cout << "\n";
cout << "Enter the amount you want to bet for this play: " << endl;
cin >> bet;
if (bet>bettotal)
{
cout << "you cannot bet more than you have, please enter"
<< "again the bet amount: "<< endl;
cin >> bet;
}
enum Status { CONTINUE, WON, LOST };
Status gameStatus;
srand(time( 0 ));
sum = rollDice(); // first roll of the dice
switch ( sum ) {
case 7:
case 11: // win on first roll
gameStatus = WON;
break;
case 2:
case 3:
case 12: // lose on first roll
gameStatus = LOST;
break;
default: // remember point
gameStatus = CONTINUE;
myPoint = sum;
cout << "Point is " << myPoint << endl;
break; // optional
}
while (gameStatus == CONTINUE ) // keep rolling
{
sum = rollDice();
if (sum == myPoint) // win by making point
gameStatus = WON;
{
if ( sum == 7 ) // lose by rolling 7
{
gameStatus = LOST;
cout << "\nYou lost the amount of your bet $" << bet << endl;
bettotal=(bettotal-bet);
cout << "now you have $" << bettotal << " to play: ";
}
}
}
if ( gameStatus == WON )
{
cout << "Player wins\n";
cout << "\nYou receive your bet: $"
<< bet <<" plus your the amount you won $"
<< bet <<"\n";
cout << "it's a total of $" << bettotal+bet
<< " available to play \n";
bettotal=bet+bet;
cout << "Please enter new the bet amount :";
cin >> bet;
}
else
{
cout << "Player loses" << endl;
cout << "\nYou lost the amount of your bet $"<<bet<<endl;
bettotal=(bettotal-bet);
cout << "now you have $"<<bettotal<<" to play: \n";
cout << "do you want to play again? Y or N ";
cin >> playagain;
}
}
while ( playagain=='Y' || playagain=='y');
}
//------------------------------------------------------------------------------
int main()
{
Craps Execution;
Execution.internalGame();
Execution.rollDice();
return 0;
}
See, much sexier this way!
Now, apply 7stud's suggestions to your code and it should work the way you intended it to.