#include <stdio.h>
int isMember();
float calculatePrice(int,int,int);
void printPlayer();
char name[4][100];
char name1[100];
int numofplayer, i, numofbook;
int member;
float game, discount, gst, subtotal, total;
int main()
{
i=0;
printf ("Your name: ");
gets (name1);
printf ("No of player: ");
scanf ("%d",&numofplayer);
while (i<numofplayer)
{
printf ("Enter Player %d: ",i+1);
scanf ("%s",name[i]);
i++;
}
printf ("How many game do you want to book?: ");
scanf ("%d",&numofbook);
isMember();
calculatePrice(isMember(),numofbook,numofplayer);
printf ("=======================\n");
printf ("Your booking detail.\n");
printf ("Your name is: %s",name1);
printf ("\nNo of player: %d",numofplayer);
printf ("\nList of player ");
printPlayer();
printf ("\nNo of game: %d",numofbook);
if (isMember()==1)
{
printf ("Status member: member \n");
}
else
{
printf ("Status member: not a member \n");
}
printf ("Total price is (including GST): %.2f",calculatePrice(isMember(),numofbook,numofplayer));
return 0;
}
int isMember()
{
printf ("Are you a member of this club?(1-yes or 0=no): ");
scanf ("%d",&member);
return member;
}
float calculatePrice(int a, int b, int c)
{
game=25;
subtotal=game*c;
subtotal=subtotal*b;
if (a==1)
{
discount=subtotal*0.1;
subtotal=subtotal-discount;
}
gst=0.06*subtotal;
total=subtotal-gst;
return total;
}
void printPlayer()
{
int i;
i=0;
while (i<numofplayer)
{
printf ("%d) ",i+1);
printf ("%s \n",name[i]);
i++;
}
}
为什么它会循环到我的isMember()
?
它一直循环然后停止,而另一个功能我甚至不确定它是否正常运行。
答案 0 :(得分:0)
它不循环。
你没有保留isMember()
的返回值,而是一遍又一遍地调用它
您应该定义一个新变量并将结果保存在其中。
res = isMember();
并在您调用res
的任何地方使用isMember()
。