Everything works fine except when you roll a non-instant win or lose, you always win on your next roll

``````#include <iostream>
#include "Crapsfunctions.h"
#include <conio.h>
#include <ctype.h>

using namespace std;

void main()
{
double Money;
double Bet;
long Roll;
long Roll2;
long Point;
long NumRolls;

//prototypes

long throwdie();
static void BackSpace ();

cout<<"Crap Game"<<endl;
cout<<"Instructions:"<<endl;
cout<<"Two die are rolled. If you roll a 7 or an 11, you win the round. If you roll a 2, 3, or 12, you lose"<<endl;
cout<<"If you roll anything else, your total is now called a point. Now you must continue rolling until you match your point"<<endl;
cout<<"and win, if you roll a 7, you lose. The value of the point stays as the first roll"<<endl;
cout<<"You have \$50.00 as your starting money"<<endl;

Money=50.00;
do{
cout<<"How much would you like to bet?"<<endl;

Roll=throwdie();

cout<<"Total number from roll of dice: "<<Roll<<endl;

switch(Roll)
{
case 7:
case 11:

//instant win

cout<<"You Win"<<endl;
Money+=Bet;
break;
case 2:
case 3:
case 12:

//instant lose

cout<<"You Lose"<<endl;
Money-=Bet;
break;
case 4:
case 5:
case 6:
case 8:
case 9:
case 10:

// point rolling

Point=Roll;
do{
NumRolls=0;
NumRolls++;

Roll2=throwdie();
cout<<"The Result of Roll "<<NumRolls<<" is "<<Roll2<<endl;
if(Roll2==Point)

//for some reason, the second roll always equals the point

{
cout<<"You Win"<<endl;
Money+=Bet;
break;
}
if(Roll2==7)
{
cout<<"You Lose"<<endl;
Money-=Bet;
break;
}
}while(Roll2!=13);
}
cout<<"Would you like to play another round of Craps? (Y/N)"<<endl;

}

//functions

//is there a way to make throwdie more random? i seem to get alot of 7's. or maybe i was born lucky =)

long throwdie()
{
srand((unsigned)time(0));
return (rand()%6)+1 + (rand()%6)+1;
}

static void BackSpace ()
{
_putch ('\b');
_putch (' ');
}

//function to read in numbers for the bet, this function works fine so you guys dont need to go through it if you want

{
char    c;
bool    Digits      (false);
int     Fraction    (0);
double  Num         (0.0);
int     Sign        (0);

while (!isspace (c = static_cast <char> (_getch ())))
{
switch (c)
{
case '+':
case '-':
if ((Sign == 0) && !Digits)
if (c == '+')
Sign = 1;
else
c= '\a';
else
c = '\a';
break;
case '.':
if (Fraction == 0)
Fraction = 1;
else
c = '\a';
break;
case '\b':
if (Fraction > 0)
{
BackSpace ();
Fraction /= 10;
if (Fraction > 0)
{
Num = static_cast <int> (Num * Fraction);
Num /= Fraction;
}
else;
}
else
if (Digits)
{
BackSpace ();
Num = static_cast <int> (Num) / 10;
if (Num == 0.0)
Digits = false;
else;
}
else
if (Sign != 0)
{
BackSpace ();
Sign = 0;
}
else
c = '\a';
break;
case '0':
if (!Digits && (Fraction == 0)) // doesn't do leading zeros
{
c = '\a';
break;
}
else;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
Digits = true;
if (Fraction > 0)
{
Fraction *= 10;
Num = Num + ((c - '0') / static_cast <double> (Fraction));
}
else
Num = (Num * 10.0) + (c - '0');
break;
default:
c = '\a';
}
_putch (c);
}
if (c == '\r')
c = '\n';
else;
_putch (c);
if (Sign < 0)
Num = -Num;
else;
return Num;
}
``````

Good for you! Next time, use CODE Tags, though.

## All 3 Replies

okay i found out whats wrong.

i ran

for(i=0;i<30;i++)
cout<<throwdie();

and i got the same number over and over

throwdie() is

srand((unsigned)time(0));
return ((rand()&6)+1+(rand()&6)+1)

how do i make it random now?

GREAT SUCCESS!!!

I put srand() in my function instead of in main so I didn't plant a new seed to flower each time. LOLOLOLOL

Even if I got no replies i think typing this stuff out helped my brain work YAY!!!

Good for you! Next time, use CODE Tags, though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.