C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.

来源:学生作业帮助网 编辑:六六作业网 时间:2024/05/11 14:00:01
C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.C语言,随即

C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.
C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.

C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.
有求不是很清楚,按我的理解写了个.
#include
#include
#include
void dice(int id);
int main(void)
{
int num;
srand(time(0));
printf("Please input the dice(1-5) you want to play\n");
printf("Input other character to exit the program.\nNow input :");
while((scanf("%d",&num) == 1) && num > 0 && num < 5)
{
dice(num);
printf("Please input the dice(1-5) you want to play :");
}
return 0;
}
void dice(int id)
{
int i = 0;
char ch,ch1;
printf("You have choosen dice %d.\n",id);
printf("You Can play 3 times at most.\n");
printf("Please input p to play,q to quit.\n");
while(i++ < 3 && (ch = getchar()))
{
if(ch == 'q')
return;
else if(ch == 'p')
{
printf("This is time %d.\n",i);
printf("you get a %d on dice %d.\n",rand() % 6 + 1,id);
if(i == 3)
printf("You have played 3 times!\n");
}
else
i--;
}
}