#includeint main( ){char sex,sports,diet;double faHeight,moHeight,a,b,myHeight,Height1,Height2;a=0.54;b= 0.923;printf("輸入你的性別\n");scanf("%c",&sex);printf("是否喜愛體育鍛煉\n"); scanf("%c",&sports);printf("是否有良好的飲食習慣\n"); scanf("%c",&diet);if(sex=='F')//判斷性別的if; {if(sports=='Y')// 判斷運動情況的if; {Height1=(((faHeight*a+moHeight)/2)*0.02);}//愛運動的增長 else{Height1=0;}//不愛運動 if(diet=='Y')//判斷飲食習慣的if; {Height2=(((faHeight*a+moHeight)/2)*0.015);}//有好的飲食習慣的增長 else{Height2=0;} //沒有好的飲食習慣 myHeight=(faHeight+moHeight)*0.54+Height2+Height1;}else({ if(sports=='Y') {Height1=(((faHeight+moHeight)*0.54)*0.02);}//愛運動的增長 else{Height1=0;}//不愛運動 if(diet=='Y')//判斷飲食習慣的if; {Height2=(((faHeight+moHeight)*0.54)*0.015);}//有好的飲食習慣的增長 else{Height2=0;} //沒有好的飲食習慣 myHeight=(faHeight*0.923+moHeight)/2+Height2+Height1; printf("%f",myHeight); myHeight=(faHeight*0.923+moHeight)/2+Height2+Height1;}printf("%f",myHeight);return 0;}
寫代碼要養成好的習慣,大括號分行,學會調試,這些基礎的問題就會迎刃而解