0
#include <stdio.h>
int main(){
int age;
char gender;
printf("Are you male or female (m/f)?");
scanf("%c",&gender);
printf("Enter your age:");
scanf("%d",&age);
printf("\n");
if(gender=="m"){
if(age>=0 && age<=55){
printf("You are a man in your best years!\n");
}
else if (age>=56 && age<=100){
printf("You are a wise man!\n");}
else{
printf("An error occurred in the program!");}
}
else if(gender=="f"){
if(age>=0 && age<=55){
printf("You are a beauty!\n");
}
else if (age>=56 && age<=100){
printf("You look young for your age!\n");}
else{
printf("An error occurred in the program!");}
}
else{
printf("An error occurred in the program!");}
return 0;
}
該程序無法正常工作。它只打印最後的else語句,即「程序發生錯誤!」。我也試圖把所有條件相同的小括號僅打印「程序中發生錯誤!」
,如:
if(gender=="f"&& age>=0 && age<=55))
但仍沒有輸出預期的結果。
'gender ==「m」' - >'gender =='m'' – BLUEPIXY
通過類推,同樣適用於'else if(gender ==「f」)' –
感謝它的工作。 – Nibesh