小编Car*_*ria的帖子

尝试在 C 语言的硬币翻转程序中使用随机数生成器

您好,我正在尝试创建一个程序,根据用户输入的抛硬币次数来计算抛硬币模拟器中正面和反面的数量。问题在于,当我尝试计算正面和反面的数量然后递增它们时,它只给我一个随机数,而不是在给定的翻转范围内。

这是我的错误的输出示例

Coin Flip Simulator
How many times do you want to flip the coin? 10
Number of heads: 1804289393
Number of tails: 846930886
Run Code Online (Sandbox Code Playgroud)

相反,我希望它像这样计数:

Coin Flip Simulator
How many times do you want to flip the coin? 10
Number of heads: 7
Number of tails: 3
Run Code Online (Sandbox Code Playgroud)

这是程序:

#include <stdio.h>
#include "getdouble.h"
#include <time.h>
#include <stdlib.h>

int main(void) {
  printf("Coin Flip Simulator\n");
  printf("How many times do you want to flip the coin? ");
  int numFlip = getdouble();
  if(numFlip == 0 …
Run Code Online (Sandbox Code Playgroud)

c random loops coin-flipping

0
推荐指数
1
解决办法
400
查看次数

标签 统计

c ×1

coin-flipping ×1

loops ×1

random ×1