C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/27 14:43:41
![C语言,随即掷5个骰子,分别把5个筛子的数字表示出来,然后自行选择其中一个掷,每个最多掷3次.](/uploads/image/z/8728558-70-8.jpg?t=C%E8%AF%AD%E8%A8%80%2C%E9%9A%8F%E5%8D%B3%E6%8E%B75%E4%B8%AA%E9%AA%B0%E5%AD%90%2C%E5%88%86%E5%88%AB%E6%8A%8A5%E4%B8%AA%E7%AD%9B%E5%AD%90%E7%9A%84%E6%95%B0%E5%AD%97%E8%A1%A8%E7%A4%BA%E5%87%BA%E6%9D%A5%2C%E7%84%B6%E5%90%8E%E8%87%AA%E8%A1%8C%E9%80%89%E6%8B%A9%E5%85%B6%E4%B8%AD%E4%B8%80%E4%B8%AA%E6%8E%B7%2C%E6%AF%8F%E4%B8%AA%E6%9C%80%E5%A4%9A%E6%8E%B73%E6%AC%A1.)
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--;
}
}