Error with multiple IF conditions

Asked

Viewed 19 times

0

The if only proceeds if it’s’m' the person’s sex, if it’s the others with || that I put will not, can anyone take away this doubt?

char sexo;
float altura, pesoideal;
printf("Qual o sexo da pessoa? \n");
scanf("%c", &sexo);

if ((sexo=='m') || (sexo=='homem') || (sexo=='masculino')) {
     printf("Qual a altura da pessoa? \n");
     scanf("%f", &altura);
     pesoideal=(72.7*altura)-58;
     printf("O peso ideal é %f", pesoideal);
}
  • When you declare char sexo; is reserving memory space for one character. When you try to compare with 'man' or 'male' you are making a mistake. The character ' serves to delimit one character. For a string (an array of characters plus the terminator character ' 0') the character is used" and string handling functions of <string. h>.

  • ((( thanks (: )))

  • You mean if I use if ' char ', with this quote I can’t name any other value for that same char in another if? or the limitation of ' ' applies to int or float?

  • I don’t understand your doubt. Take a look at the C language data types in some introductory material.

  • All right, I’ll study some more

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.