0 c
我应该制作一个多次播放的骰子游戏.我不是在寻找答案,有点想看看我做错了什么.我希望for循环将int ia值指定为0,然后运行骰子卷,然后将一个添加到i,直到我 > 50.感谢提前.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main(){
int rollDie1, rollDie2, keyValue = 0, win = 0, lose = 0, reroll = 0, i;
srand(time(NULL)); // call this only once – seed the random generator
for (i = 0 ; i < 50 ; i++);
{
rollDie1 = rand() % 6 + 1; // in the range of 1 - 6
rollDie2 = rand() % 6 + 1; // in the range of 1 - 6
keyValue = rollDie1 + rollDie2;
if ( keyValue == 7 || keyValue == 11 )
{
printf ("Player wins on the first roll \n");
}
if ( keyValue == 2 || keyValue == 3 || keyValue == 12 )
{
printf("Sorry, you lost on the first roll \n");
}
if ( keyValue == 4 || keyValue == 5 || keyValue == 6 || keyValue == 8 || keyValue == 9 || keyValue == 10 )
{
printf("Reroll! \n");
}
}
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
;在for循环的末尾有一个不应该存在的东西.
for (i = 0 ; i < 50 ; i++);
Run Code Online (Sandbox Code Playgroud)
应该
for (i = 0 ; i < 50 ; i++)
Run Code Online (Sandbox Code Playgroud)
否则for循环中没有任何东西,{}遗嘱中的内容只执行一次,因为这是一个单独的陈述.