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