我为学校工作的项目基本上是一个网球计数器(不要介意'while'外面的空白'if',我仍在努力),它有以下代码:
#include <stdio.h>
int main () {
int giocatore1=0;
int giocatore2=0;
int punto;
while(giocatore1!=40 && giocatore2!=40) {
do
scanf("%d", &punto);
if(punto=1) {
if(giocatore1<30) {
giocatore1+=15;
} else giocatore1+=10;
} else if(punto=2) {
if (giocatore2<30) {
giocatore2+=15;
} else giocatore2+=10;
}
}
}
我希望它能正确编译,但它却给了我那些编译错误:
In function 'int main()':
12 6 [Error] expected 'while' before '(' token
12 16 [Error] expected ';' before '{' token
16 44 [Error] 'ptintf' was not declared in this scope
17 5 [Error] 'else' without a previous 'if'
似乎它只是麻木,不读取第一个'if'里面的命令。如果你能帮忙,我将不胜感激。
有1个do
错型,2个=
应该是==
。这段代码应该没问题。
#include <stdio.h>
int main () {
int giocatore1=0;
int giocatore2=0;
int punto;
while(giocatore1!=40 && giocatore2!=40) {
scanf("%d", &punto);
if(punto==1) {
if(giocatore1<30) {
giocatore1+=15;
} else giocatore1+=10;
} else if(punto==2) {
if (giocatore2<30) {
giocatore2+=15;
} else giocatore2+=10;
}
}
return 0;
}