C中的骰子游戏帮助[关闭]

问题描述 投票:-6回答:1
这是我在StackOverflow上的第一篇文章,我正在用C创建骰子游戏。我试图弄清楚如何使计分系统正常工作

下面是我的骰子游戏的代码

#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; }

c
1个回答
-1
投票
将类似的内容添加到您的循环中。

char t; printf("Do you want to continue? (Q: Exit, Any other key to continue)\n"); scanf("%s", &t); if (t == 'Q') { break; }

© www.soinside.com 2019 - 2024. All rights reserved.