TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Contabilidade de Monografia

Por:   •  13/5/2015  •  Monografia  •  684 Palavras (3 Páginas)  •  147 Visualizações

Página 1 de 3

#include <stdio.h>

#include <stdlib.h>

#include <time.h> /* contains prototype for function time */

/* enumeration constants represent game status */

enum Status { CONTINUE, WON, LOST };

int rollDice( void ); /* function prototype */

/* function main begins program execution */

int main( 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;

printf( "Point is %d\n", myPoint );

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 */

...

Baixar como (para membros premium)  txt (2.4 Kb)   pdf (42.6 Kb)   docx (11.8 Kb)  
Continuar por mais 2 páginas »
Disponível apenas no TrabalhosGratuitos.com