0
I need to answer a question that asks to type two words, like this:
is a canteen and there are 4 possible requests.
Two options for food: lasagna and stroganoff;
Two drink options: juice and soda.
I find problems with the code because when I type the first word scanf asks, the program already closes.
And it is necessary that the user can type interspersed between uppercase and minuscule, how to do so that there is no differentiation?
float total_a_pagar;
char comida[20];
char bebida[20];
scanf("%c\n%c", &comida, &bebida);
if (strcmp(comida, "Lasanha") == 0 && strcmp(bebida, "Refrigerante") == 0)
{
total_a_pagar = 8+3;
printf("%.1f\n", total_a_pagar);
}
else if (strcmp(comida, "Lasanha") == 0 && strcmp(bebida, "Suco") == 0)
{
total_a_pagar = 8+2.5;
printf("%.1f\n", total_a_pagar);
}
else if (strcmp(comida, "Estrogonofe") == 0 && strcmp(bebida, "Refrigerante") == 0)
{
total_a_pagar = 11+3;
printf("%.1f\n", total_a_pagar);
}
else if (strcmp(comida, "Estrogonofe") == 0 && strcmp(bebida, "Suco") == 0)
{
total_a_pagar = 11+2.5;
printf("%.1f\n", total_a_pagar);
}
For reading a string (string) the tag is %s and not %c. Note that the name of an array is already the address of the beginning of the array. Trade scanf("%c n%c", &food, &drink); by scanf("%s n%s", food, drink);
– anonimo
To compare by ignoring the letter box you can use the strcasecmp function of <strings. h>.
– anonimo
regarding:
char comida[20];
 char bebida[20];
 scanf("%c\n%c", &comida, &bebida);
should be:char comida[20];
 char bebida[20];
 if( scanf("%19s\n%c-19s", comida, bebida) !=2) {// handle error}
– user3629249