Hey guys! First post here. I've heard a lot of good things about this cite from from CS Majors at my school so I thought I might check it out.
I'm writing a craps game program right now. If you aren't familiar with the game of craps, here's a quick rundown:
There are two 6-sided dice. You roll both of them. If you roll a 7 or an 11, then you win. If you roll a 2, 3, or 12 then you lose. If you roll any other number, that number is called the "point". In order to win, you must keep rolling until you roll that point. However you will lose if you roll a 7 before the point is rolled.
My issue:
I'm trying to have my function return a value telling main() whether player 1 won or lost. Because if he wins, then he keeps rolling until he loses. At which player 2 will play until he loses. So on and so forth. Right now I have the function as a void, as I only have it printing out what happens. So I'm trying to figure out a way to tell the main function that he either won or lost. Or should I simply put in a bool value within the function gamePlay() and reference it in main when I need to? Or is there some type of easier way to do this? Thanks in advance!
yes you can return a bool value and process that in main
something like :
1 2 3 4 5 6 7 8 9 10 11 12
bool shouldPlayerOneContinue ()
{
returntrue;
}
//...
int main ()
{
if ( shouldPlayerOneContinue() ) // same as if ( shouldPlayerOneContinue() == true )
praiseHim ();
else
goHome ();
}