2
In one of the exercises of a book I’m reading, I’m asked to trace a person’s "profile" according to the year she was born (like those Facebook tests) but in order to limit the possibility of what is typed, I put a if
to signal an error, but even with the value being positive for the if
, the block of else
keeps running, how can I solve?
int main(void){
setlocale(LC_ALL,"");
int y,a,b,c;
printf("Digite seu ano de nascimento (quatro digitos)\n");
scanf("%d",&y);
if (y>9999 && y<1000) printf("Ano inválido");
else {
b=y%100;
a=y/100;
c=a+b;
c=c%5;
switch(c){
case 0:printf("Tímido\n"); break;
case 1:printf("Sonhador\n"); break;
case 2:printf("Paquerador\n"); break;
case 3:printf("Atraente\n"); break;
case 4:printf("Irresistível\n"); break;
}
}
return 0;
}
What is your problem?
– Maniero
even putting a year like 20000 or 3, still is given a result of the Else block
– motorola
did not understand, but in the question were cut some words of what I put, so it was difficult to understand
– motorola
@If you’re talking about my edition, I haven’t removed anything else. You can confirm this in the history.
– Pablo Almeida
it wasn’t your issue, actually a few words I put in the question in the appeared
– motorola
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero