我已经单独测试了每个部分,我知道它们可以工作,问题是当我将函数 roll_dice 粘贴回或虎钳 verse 时。当我将两者编译在一起时,我得到错误 C2143 missing ';' 在第 32 行的“type”之前,它是 play_game 函数。有人可以告诉我为什么我在他们分开工作时会出现这个错误,但当他们放在一起时却不工作。这是一个掷骰子游戏,我是使用 c 的初学者。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX_DIE 6
#define true 1
#define false 0
int num1 = 0;
int num2 = 0;
int roll = 0;
int point = 0;
int wins = 0;
int losses = 0;
int keep_rolling = 1;
int main(void)
{
void roll_dice(int num1, int num2, int roll);
{
srand(time(NULL ));
num1 = ("%d", rand() % MAX_DIE + 1);
num2 = ("%d", rand() % MAX_DIE + 1);
roll = (num1 + num2);
printf("this is your number : %d\n", num1);
printf("this is your 2nd number : %d\n", num2);
printf("this is your total : %d\n", roll);
}
void play_game(int wins, int losses, int point, int roll);
{
if ((roll == 7) || (roll == 11))
{
printf("you rolled %d you won \n", roll);
wins += 1;
}
else if ((roll == 2) || (roll == 3) || (roll == 12))
{
printf("you rolled %d you lost \n", roll);
losses += 1;
}
else if ((roll == 1) || (roll == 4) || (roll == 5) || (roll == 6)
|| (roll == 8) || (roll == 9) || (roll == 10))
{
printf("you have pointed : %d\n", roll);
point = roll;
printf("you rolled %d you pointed \n", roll);
while (keep_rolling = 1)
{
void roll_dice(int num1, int num2, int roll);
if (roll == point)
{
printf("you rolled %d you won \n", roll);
wins += 1;
return keep_rolling = false;
}
else if (roll == 7)
{
printf("you rolled %d you lost \n", roll);
losses += 1;
return keep_rolling = false;
}
else
{
printf("you rolled : %d\n", roll);
printf("your point is : %d\n", point);
}
}
}
}
}