[英]Debugging my c program, number guessing game
我需要調試該程序的幫助,但不知道出了什么問題。 我正在使用膩子和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:錯誤:(報告了每個未聲明的標識符僅對project2total.c:49一次:錯誤:它出現在每個函數中。)
C區分大小寫。 在您的函數中,沒有聲明PlayerTurn
,但是您似乎已經聲明了playerTurn
。 假設這實際上是您要引用的變量,只需將大寫P校正為小寫即可。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.