所以我试图做一名羽毛球记分员。 并遇到问题。
#include<stdio.h>
int scorekeeper();
char home[21]="HOME",away[21]="AWAY",choice3;
void scoreboard();
int score1=0,score2=0,set1=0,set2=0,m=1;
int main()
{
int choice1,choice2,setnum;
char buf[50];
printf("\t\t\t/////////////////////////////////\n\t\t\t/ BADMINTON SCOREKEEPER\t/\n\t\t\t/////////////////////////////////\n\n");
do {
printf("Do you want to enter players' or teams' names?\n1-Yes\n2-No\n:>>");
scanf("%d",&choice1);
switch(choice1) {
case 1: {
do {
printf("\nPlease enter HOME player's or team's name(max 20 characters including space)\n:>>");
fgets(buf, sizeof buf, stdin);
scanf(" %20[^\n]",&home);
printf("\nPlease enter AWAY player's or team's name(max 20 characters including space)\n:>>");
fgets(buf, sizeof buf, stdin);
scanf(" %20[^\n]",&away);
do {
printf("\n\n%.20s VS %.20s\n\n1.Confirm\n2.Edit\n:>>",home,away);
fgets(buf, sizeof buf, stdin);
scanf(" %d",&choice2);
if(choice2!=1&&choice2!=2)
printf("\n***ERROR. INVALID INPUT***\n\n");
} while(choice2!=1&&choice2!=2);
} while(choice2==2);
break;
}
case 2: {
printf("\nSet up to default:\n%s VS %s\n\n",home,away);
break;
}
default: {
printf("\n***ERROR. INVALID SELECTION***\n\n");
break;
}
}
} while(choice1!=1&&choice1!=2);
do {
printf("\n\nHow many sets you want to play?\n(enter 1,3 or 5)\n:>>");
scanf("%d",&setnum);
if(setnum!=1&&setnum!=3&&setnum!=5)
printf("\n\n***INVALID INPUT. PLEASE RE-ENTER***\n\n");
} while(setnum!=1&&setnum!=3&&setnum!=5);
printf("\n\nSTART THE MATCH\n===============\n\n");
while(setnum>0) {
--setnum;
score1=0;
score2=0;
while(score1<21&&score2<21) {
scoreboard();
scorekeeper();
}
if (score1==21&&score2==20||score1==20&&score2==21)
while(score1!=score2+2&&score2!=score1+2) {
scoreboard();
scorekeeper();
if(score1==29&&score2==29)
break;
}
if(score1==29&&score2==29) {
scoreboard();
scorekeeper();
}
if(score1>score2)
++set1;
else
++set2;
scoreboard();
++m;
printf("\n\nEND OF SET\n\n");
if(set1==set2+2||set2==set1+2)
break;
}
return 0;
}
void scoreboard()
{
int a,b,c,d,e,f,g,h,i,j;//here comes the problem
if(m==1) {
a=score1;
b=score2;
printf("\n\n\t\t S\n----------------------------\n|%-20s|%2d|%2d|\n----------------------------\n|%-20s|%2d|%2d|\n----------------------------\n\n",home,set1,a,away,set2,b);
} else if(m==2) {
c=score1;
d=score2;
printf("\n\n\t\t S\n-------------------------------\n|%-20s|%2d|%2d|%2d|\n-------------------------------\n|%-20s|%2d|%2d|%2d|\n-------------------------------\n\n",home,set1,a,c,away,set2,b,d);
} else if(m==3) {
e=score1;
f=score2;
printf("\n\n\t\t S\n-------------------------------\n|%-20s|%2d|%2d|%2d|\n-------------------------------\n|%-20s|%2d|%2d|%2d|\n-------------------------------\n\n",home,set1,a,c,e,away,set2,b,d,f);
}
return;
}
int scorekeeper()
{
printf("\n\nHOT KEYS LIST:\nA-%s SCORES\nL-%s SCORES\n\n",home,away);
scanf(" %c",&choice3);
switch(choice3) {
case 'A':
case 'a': {
++score1;
break;
}
case 'L':
case 'l': {
++score2;
break;
}
default: {
printf("\n\n***ERROR. INVALID INPUT***\n\n");
break;
}
}
return score1,score2;
}
我想要做的是在第1组中,程序将分配得分1和1的值。得分2分别为a&amp; b。然后进入下一组,它将覆盖score1&amp;的值。在将它们分配给c&amp; d之前,得分2回到0。我怎么想这样做而不影响存储在&amp; b?
中的值