您好我有這個代碼在這裏試圖詢問用戶有關的位置。當用戶輸入位置它只是說再見。我的代碼中有什麼錯?如果 - 其他程序
#include<stdio.h>
int main()
{
char location[15];
printf("1:Greencourt\n");
printf("2:Corianthans\n");
printf("3:Shop\n");
printf("Enter a location\n");
scanf("%s",location);
if(location=="Greencourt")
printf("Bisleri bottle cost 25 rupees\n");
else
if(location=="Shop")
printf("Bisleri bottle cost 15 rupees\n");
else
if(location=="Corianthans")
printf("Bisleri bottle cost 50\n");
else
printf("Bye");
return 0;
}
這裏是輸出
1:Greencourt
2:Corianthans
3:Shop
Enter a location
Shop
Bye
更好地使用STRCMP值compaiting串 –
由於標籤與C的問題++,我建議你使用'std :: string'而不是普通的char數組。 – soon
請縮進您的代碼。 –