1
因此,在我的程序中没有语法错误,这是一个逻辑错误。我的问题是,当我尝试运行它时,只有我的printf
语句会执行,但在此之后它会关闭我的程序,不会让我的while loop
询问任何数据,直到用户放入-1
来停止我的while循环。我的程序在关闭前不会运行我的while循环
#include <stdio.h>
// prototypes
void updateLevel(int PlayerPoints, int playerLevels[]);
void displayLevels(int ArrayName[]);
//main begins
int
main (void){
//arrays and varibles
int playerLevels[6] = {0};
int playerPoints = 0;
printf("Player points (-1 to quit) ");
scanf("%d" , &playerPoints);
//while loop to process input data
while(playerPoints =! -1){
scanf("Player points (-1 to quit) %d" , &playerPoints);
updateLevel(playerPoints, playerLevels);
}
displayLevels(playerLevels);
return(0);
}
//main ends
//functions
void updateLevel(int playerPoints, int playerLevels[]){
if(playerPoints >=50)
playerLevels[6]++;
else if (playerPoints >=40)
playerLevels[5]++;
else if (playerPoints >= 30)
playerLevels[4]++;
else if (playerPoints >= 20)
playerLevels[3]++;
else if (playerPoints >= 10)
playerLevels[2]++;
else
playerLevels[1]++;
}
void displayLevels(int playerLevels[]){
printf("T O T A L S\n");
printf("Level 1 %d\n", playerLevels[1]);
printf("Level 2 %d\n", playerLevels[2]);
printf("Level 3 %d\n", playerLevels[3]);
printf("Level 4 %d\n", playerLevels[4]);
printf("Level 5 %d\n", playerLevels[5]);
printf("Level 6 %d\n", playerLevels[6]);
}
omg我甚至没有注意到操作员,但非常感谢你!它的工作原理非常感谢你! –
@GabrielFregoso没问题。这是一个错字。:) –