c语言掷骰子代码
使用c语言编写一个简单的掷骰子游戏,能运行就行,急求
游戏按以下方式进行:系统会掷骰子,得到一个1-6之间的整数,给玩家两次猜的机会,当玩家两次都不对,系统会提示机会已经用完,并且询问是否重玩。 我刚刚已经找了机器试过并做了少许修改,可以运行了。
#include #include #include #include void main() { int num, n; char ch; srand((unsigned)time(NULL)); do { num = rand() % 6 + 1; printf("Input a number:(1-6)"); scanf("%d", &n); if (n == num) { printf("Right!"); ch = 'n'; } else { printf("Wrong! Input another number:(1-6)"); scanf("%d", &n); if (n == num) { printf("Right!"); ch = 'n'; } else { printf("Wrong! Play again?(y/n)"); scanf("%c", &ch);/*去除前面一次输入时最后的换行符*/ scanf("%c", &ch); } } } while (ch == 'y' || ch == 'Y'); } 。
答:正确的代码如下: main() { int a[9],i,k,j,s=0; for(i=1;i=1&&j=a[i-1]&&j>=a[k-1]) {printf(...详情>>