2
I need the user to enter the numbers 1, 2 or 3 to choose the locations, and if not select one, ask again.
But when entering the number 0 or 4, for example, it returns to the start screen (that would be the menu, destinations, costs and exit).
I need him to say "Enter a valid city code" and question again one of the three numbers.
What I did wrong?
printf("Selecione a opcao desejada:\n 1 - Destinos \n 2 - Custos \n 3 - Sair\n");
scanf("%d", &op);
switch(op) {
case 1 : printf("\n1 - Destinos:\n\n Codigo da cidade Valor da passagem por pessoa\n\n");
printf(" 1 - Nova York ===> R$3.231,00\n");
printf(" 2 - Londres ===> R$3.789,00\n");
printf(" 3 - Dubai ===> R$4.932,00\n\n");
printf("Informe o numero de seu destino\n");
scanf("%d", &destino);
if (destino <= 0 && destino > 3) {
do{
printf("Informe um codigo de cidade valido.\n");
scanf("%d", &destino);
} while (destino <= 0 && destino > 3);
}
It is impossible for a value to be <= 0 and simultaneously > 3. Review the definition of logic operators && e ||.
– anonimo
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero