Hi guys, I need a bit of help with a C program I'm writing for a class. The program will compile fine (gcc), but I need it to output values and it simply will not have it. Here's the code:
I know it's a little long, but if someone notices something blaringly obvious please let me know!
Thanks!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
enum Status { CONTINUE, WON, LOST };
int rollDice( void ); /* function prototype */
int playgame(void);
int rolls;
int main(void)
{
/* Roll dice, calculate sum and display results */
int rollDice( void )
{
int die1; /* first die */
int die2; /* second die */
int workSum; /* sum of dice */
die1 = 1 + ( rand() % 6 ); /* pick random die1 value */
die2 = 1 + ( rand() % 6 ); /* pick random die2 value */
workSum = die1 + die2; /* sum die1 and die2 */
/* display results of this roll */
return workSum; /* return sum of dice */
} /* end function rollRice */
//end Main
int playgame(void)
{
int sum; /* sum of rolled dice */
int myPoint; /* point earned */
enum Status gameStatus; /* can contain CONTINUE, WON, or LOST */
/* randomize random number generator using current time */
srand( time( NULL ) );
sum = rollDice(); /* first roll of the dice */
/* determine game status based on sum of dice */
switch( sum )
{
/* win on first roll */
case 7: case 11: gameStatus = WON;
break;
/* lose on first roll */
case 2: case 3: case 12: gameStatus = LOST;
break;
/* remember point */
default: gameStatus = CONTINUE;
myPoint = sum;
break; /* optional */
} /* end switch */
/* while game not complete */
while ( gameStatus == CONTINUE )
{
sum = rollDice(); /* roll dice again */
/* determine game status */
if ( sum == myPoint )
{
/* win by making point */
gameStatus = WON; /* game over, player won */
} /* end if */
else
{
if ( sum == 7 )
{
/* lose by rolling 7 */
gameStatus = LOST; /* game over, player lost */
} /* end if */
} /* end else */
} /* end while */
if((gameStatus = WON)) {
rolls = sum;
printf( "%d", sum);
}
else if((gameStatus = LOST)) {
rolls = (sum * (-1));
printf("%d", sum);
}
return sum; /* indicates successful termination */
} /* end playgame */
return 0;
} //end Main
I know it's a little long, but if someone notices something blaringly obvious please let me know!
Thanks!