weixin_55639971
忄真 Ꮤ
采纳率100%
2021-02-28 21:27

我正在自学c语言,跟着书上打了这个代码但一直报错,哪位大佬能看一下?

已采纳

 

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX_NUMBER 100
void initialize_number_generator(void);
int new_secret_number(void);
void read_guesses(int secret_number);

int main(void)
{
	char command;
	int secret_number;

	printf("Guess the secret number between 1 and %d.\n\n",MAX_NUMBER);
	initialize_number_generator();
	do{
		secret_number =new_secret_number();
		printf("A new number has chosen.\n");
		read_guesses(secret_number);
		printf("Play again?(Y/N)");
		scanf("%c",command);
		printf("\n");
	}
	while(command=='y'||command=='Y');
	return 0;
}
void initialize_number_generator(void)
{
	srand((unsigned) time(NULL));
}
int new_secret_numbre(void)
{
	return rand() %MAX_NUMBER + 1;
}
void read_guesses(int secret_number);
{
	int guess,num_guesses=0;
	for(;;)
	{
		num_guesses++;
		printf("Enter guess:");
		scanf("%d",&guess);
		if(guess==secret_number)
		{
			printf("You won in %d guesses!\n\n",num_guesses);
			return;
		}
		else if (guess<secret_number)
			printf("Too low;try again.\n");
		else
			printf("Too high;try again.\n");
	}
}

error C2449: 在文件范围内找到“{”(是否缺少函数头?)
 error C2059: 语法错误:“}”

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • ChengCheng_0211 ChengCheng_0211 1月前

    scanf("%c",command);应该是scanf("%c",&command);

    int new_secret_numbre(void)函数名字写错了

    void read_guesses(int secret_number);函数定义的时候多加了;

    点赞 评论 复制链接分享