我正在为一款名为 MTG(万智牌)的游戏制作一个小型的生命和毒物计数器,我遇到了一些无法编译的问题,有人可以帮忙吗?抱歉,如果它们很简单,我是 C 新手......
#include <stdio.h>
#include <stdlib.h>
int life = 20;
int poison = 0;
int amount;
char pn;
char lp;
int main(int argc, char* argv[]) {
while(1){
system("clear");
printf("Life:%d\nPoison Counters:%d\n\n\n", life, poison);
printf("\n\n<Life or Poison>(l/p) <positive or negative>(+/-) <amount>(#)\n\n\n>>>");
scanf("\n\n%c %c %d", &lp, &pn, &amount);
if(lp == 'l'){
if(pn == '+'){
life = life + amount;
}
else{
life = life - amount;
}
}else if(lp == 'p'){
if(pn == '+'){
poison = poison + amount;
}
else{
poison = poison - amount;
}
}else if(lp == 'q'){
break;
}
}
}
}
return 0;
}
这就是终端告诉我的......
mtglife.c:36:2: error: expected identifier or ‘(’ before ‘}’ token
mtglife.c:37:1: error: expected identifier or ‘(’ before ‘return’
mtglife.c:38:1: error: expected identifier or ‘(’ before ‘}’ token
最佳答案
您没有正确关闭主函数。
#include <stdio.h>
#include <stdlib.h>
int life = 20;
int poison = 0;
int amount;
char pn;
char lp;
int main(int argc, char* argv[]) {
while(1){
system("clear");
printf("Life:%d\nPoison Counters:%d\n\n\n", life, poison);
printf("\n\n<Life or Poison>(l/p) <positive or negative>(+/-) <amount>(#)\n\n\n>>>");
scanf("\n\n%c %c %d", &lp, &pn, &amount);
if(lp == 'l'){
if(pn == '+'){
life = life + amount;
}
else{
life = life - amount;
}
}else if(lp == 'p'){
if(pn == '+'){
poison = poison + amount;
}
else{
poison = poison - amount;
}
}else if(lp == 'q'){
break;
}
}
return 0;
}
关于c - 错误: expected identifier or ‘(’ before ‘}’ token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24346965/