2017-05-15 51 views
0
#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()循環?我的int上的循環函數是()

它一遍又一遍地循環,然後停止,另一個功能,我甚至沒有信心,如果它運行正常。

<code>enter image description here</code>

回答

1

它不循環。
而不是保留從isMember()返回的值,你一遍又一遍地調用它。
您應該定義一個新變量並將結果保存在其中。

res = isMember(); 

,並使用res任何你叫isMember()

+0

謝謝@Amirag – zame