My code need to execute only one case path from 3x2 table which is; for Male 140 to 160 cm: short, 161 to 180 cm: medium; 181 to 199 cm: tall and for Female 120 to 140 cm: short, 141 to 165 cm: medium and 166 to 180 cm: tall.
For example, if i enter 153 cm woman, output is need to be only medium. But now my code gives output if i enter 153 cm woman, medium & tall together at the end.
How can i edit this code so far to execute for only one case for two combinations, age and length, and one of the three option for length; for example if i enter 153 cm woman, it will need say only medium.
#include <stdio.h>
int main()
{
int length;
char gender;
printf("enter gender: ");
scanf("%c", &gender);
printf("enter length: ");
scanf("%d", &length);
if (gender == 'M' || 'm') {
if (length <= 140 && length <= 160 ) {
printf ("short");
}
if (length <= 161 && length <= 180 ) {
printf ("medium");
}
if (length <= 181 && length <= 199 ) {
printf ("tall");
}
if (gender == 'W' || gender == 'w') {
if (length <= 120 || length <=140) {
printf("short");
if (length <=141 || length <=165) {
printf ("medium");
if (length <=166 || length <=180) {
printf ("tall");}
else {
printf("error");
}
}
}
}
}
return 0;
}
For below lines, it has to be length >= 161. Pls check similar lines for this.
if (length <= 161 && length <= 180 ) {
printf ("medium");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With