下面是我的骰子游戏的代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int numberRolls = 0;
int randomNumb = 0;
int guessedNumb;
int total1;
int total2;
printf("The die will roll six times and report what each roll was.\nPick a number between 1 and 6!");
for (numberRolls = 1; numberRolls < 7; numberRolls++)
{
printf("\nHit any number key when you are ready.\n");
scanf("%d", &guessedNumb);
srand(time(NULL));
randomNumb = (rand() % 6) + 1;
{
printf("\nDice roll %d was %d.\n", numberRolls, randomNumb);
}
if (guessedNumb == randomNumb)
;
{
total1 += 1;
printf("You have won %d out of 6 die rolls\n", total1);
}
if (total1 <= 4)
;
{
printf("\nYou have won more that 4 out of 6 dice rolls\n");
}
}
return 0;
}
char t;
printf("Do you want to continue? (Q: Exit, Any other key to continue)\n");
scanf("%s", &t);
if (t == 'Q') {
break;
}