【发布时间】:2013-12-29 19:55:47
【问题描述】:
我的任务是执行一个程序,该程序将 2 个骰子掷出 x 次,然后打印出每个数字 (2-12) 的结果。这就是我已经走了多远,但正如你所见,我被困住了。我不知道如何将数组从 throw_dice 函数获取到 print_result 函数。我也不知道如何计算和打印出每个数字的实际百分比。我不是要求有人为我完成代码,而是一些提示!
提前谢谢。
#include <stdio.h>
#include <time.h>
int array[11];
int count=0;
int get_no_of_throws()
{
int throws;
printf("How many throws? ");
scanf("%i", &throws);
return throws;
}
int throw_dice(int throws)
{
int dice1;
int dice2;
int sum=0;
srand(time(NULL));
for(count=0;count<11;count++)
{
array[count]=0;
}
for(count=0;count<throws; count++)
{
dice1=rand()%6+1;
dice2=rand()%6+1;
sum=dice1+dice2;
++array[count];
}
return array[count];
}
void print_results(array)
{
?????
}
int main()
{
int throws;
get_no_of_throws();
throw_dice(throws);
print_results(array);
return 0;
}
【问题讨论】:
-
如果您将这个“C”标记为“C”,您将收到 很多 条评论 - 可能太多了。