函数调用问题
程序代码:#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<time.h>
#define N 6
int roll_dice(void);
bool play_game(void);
int main()
{
bool m;
char i;
srand((unsigned)time(NULL)); //修改后将roll_dice函数中的srand写到了前面,现在问题是随机取数我不是把它设置成roll_dice函数么?那么初始化也就是
m = play_game();//1 //srand((unsigned)time(NULL));为什么还要写入main函数中呢?
do{
if(m == true){
printf("\nYou win!\n\n");
}
if(m == false){
printf("\nYou lose!\n\n");
}
printf("Play again? ");
scanf("%c",&i);
printf("\n");
if (i == 'Y'||i =='y')
m = play_game();
} while(i != 'Y'||i !='y');
return 0;
}
int roll_dice(void)
{
int a1, a2;
// srand((unsigned)time(NULL)); //找到了原因,
a1 = rand() % 6;
a2 = rand() % 6;
return a1 + a2;
}
bool play_game(void)
{
int j = 0, k = 0;
printf("You rolled: ");
j = roll_dice();
printf("%d\nYou point is:%d\n",j, j);
switch(j){
case 7: case 11:
return true;
case 2: case 3: case 12:
return false;
default:
while(1){
k = roll_dice();
printf("You rolled: %d\n",k);
if(k == j ) return true;
if(k == 7) return false;
}
}
}
模拟骰子(2个)游戏,第一次点数之和7或11胜,2.3.12败。其他继续下一轮,第二次如果还是第一次那个数,胜。第二次为7,败。其他继续。
问题就一个,当我单独调试play_game时没什么问题,但整体输出时从注释1直接调到最后,好像都不经过play_game函数,帮我查查main函数里面出现了什么问题,虚心求教



[ 本帖最后由 达尔文 于 2015-9-23 21:59 编辑 ]










不是么?