Hallo Ich habe diesen Code hier versuchen den Benutzer über den Standort zu fragen.Wenn der Benutzer den Ort gibt es nur sagt tschüss.Was ist falsch in meinem Code?If - else Programm
#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;
}
Hier ist die Ausgabe
1:Greencourt
2:Corianthans
3:Shop
Enter a location
Shop
Bye
Bessere Nutzung strcmp vergleichen für Streicher –
Da die Frage mit C markiert ++ compaiting, Ich würde vorschlagen, dass Sie 'std :: string' anstelle von einfachen char-Arrays verwenden. – soon
Bitte den Code einrücken. –