私は各部分を個別にテストしましたが、それらが機能することを知っています。問題は、関数 roll_dice を元に戻すか、逆に貼り付けるときです。2 つを一緒にコンパイルすると、エラー C2143 が見つかりません '; play_game 関数である 32 行目の「type」の前。別々に作業するとこのエラーが発生するのに、一緒にすると機能しない理由を教えてください。これはクラップス ゲームで、私は 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);
}
}
}
}
}