#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int a =1, d1, d2;
int print_opening_msg(void);
void display_rules(void);
void show_menu(void);
int roll_dice(void);
int show_die(int, int);
char rulesans, option, dummy;
int main(void)
{
srand(time(NULL));
while(a==1)
print_opening_msg();
return 0;
}
int print_opening_msg()
{
printf("Welcome to Craps v1.0 Get ready to get your game on!nn");
show_menu();
return 0;
}
void show_menu(void)
{
char choice;
do
{
printf("nnMenunn");
printf("P = Playn");
printf("R = Rulesn");
printf("Q = Quitnn");
scanf("%c%c",&choice, &dummy);
switch(choice)
{
case 'P': roll_dice();
break;
case 'R': display_rules();
break;
case 'Q': printf("Quitting Game!n");
exit(0);
break;
default: printf("Invalid choice!n");
break;
}
} while (choice != 'Q' || 'R');
}
void display_rules(void)
{
printf("A player rolls 2 6-sided dice of which the sum of the dice is calculated.nn");
printf("If the sum is 7 or 11 on the first roll, the player wins.nn");
printf("If the sum is 2, 3, or 12 on the first roll, the player loses.nn");
printf("If the sum is other than above on the first roll, nthen the sum is known as the "point".nn");
printf("The player then continues rolling the dice attempting to nobtain the "point" value.nn");
printf("If the player rolls a 7 on any subsequent roll attempting to n"make the point", the player loses.nn");
printf("Do you understand these rules? ");
scanf("%c%c", &rulesans, &dummy);
switch(rulesans)
{
case 'Y': show_menu();
break;
case 'N': display_rules();
break;
default: display_rules();
}
}
int roll_dice()
{
d1 = rand() % 6 + 1;
d2 = rand() % 6 + 1;
return d1+ d2;
}
int show_die(int d1, int d2)
{
printf("%d die 1", d1);
printf("%d die 2", d2);
return 0;
}