gpt4 book ai didi

c - 调试我的 C 程序,猜数字游戏

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:06 25 4
gpt4 key购买 nike

我需要调试此程序的帮助,但我不知道哪里出了问题。我正在使用 putty 和 Vi 编辑器来运行我的程序。这是我的代码:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <malloc.h>

int main(void) {

int playerNumber = 0;
int number = 0;
int playerInput = 0;
int guess = 0;
char input;
char str[6] = {0};
int playerA = 0;
int playerB = 0;
int passA = 3;
int passB = 3;
int i = 0;
int playerTurn = 0;


srand(time(NULL));
playerNumber = 1 + rand() % 2; /* Random number is generated */

printf("\nPlayer %d goes fist\n", playerNumber);

printf("Player Number?\n");


while (playerNumber != playerInput) {
scanf("%d", &playerInput);

if (playerNumber != playerInput) printf("You Have to wait your turn.\nPlayer number?\n");

playerNumber = playerA;

if (playerA = 1) playerB = 2;
else playerB = 1;

srand(time(NULL));
number = 0 + rand() % 100; /* Random number is generated */

printf("Enter Your Guess, 0 - 100 or Pass: "); /* Input your guess */

while(number != guess) {

for(i = 1; i < 1000; i++) {
if (i%2 == 1) playerTurn = playerA;
else PlayerTurn = playerB;
scanf("%s", str);

if (strcmp(str, "pass") == 0) printf("Player Number?\n");
else {
guess = atoi(str);
if(guess < number) /* if the guess is lower, output: the guess is to low */
printf("Your guess was to low.\n Player Number:\n ");

else if(guess > number) /* if the guess is higher, output: the guess is to high */
printf("Your guess was to high.\n Player Number:\n ");

else /* is the guess is equial to the random number: Success!! */
printf("Yes!! you got it!\n");
return 0;
}
}
}
}

这是我得到的错误:project2total.c:在函数 main' 中:
project2total.c:49: error:
PlayerTurn' 未声明(首次在此函数中使用)project2total.c:49: error: (每个未声明的标识符只报告一次project2total.c:49: 错误:对于它出现的每个函数。)

最佳答案

C 区分大小写。在您的函数中,没有声明 PlayerTurn,但您似乎已经声明了 playerTurn。假设这实际上是您要引用的变量,只需将大写 P 更正为小写即可。 :)

关于c - 调试我的 C 程序,猜数字游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15890146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com