I wrote the following program in C and when the input is 'U', 'F' and '27', the output is 'The driver is not insured.' Can anyone please explain why? Shouldn't the output be, 'The driver is insured?'
The Program:
#include <stdio.h>
int main() {
int age;
char sex, ms;
printf("Enter the marital status(M for married and U for unmarried), sex (M for male and F for female) and age of driver:\n");
scanf("%c %c %d", &ms, &sex, &age);
if (ms == "M")
printf("The driver is insured\n");
else if (age > 30)
printf("The driver is insured\n");
else if (sex == "F") {
if (age > 25)
printf("The driver is insured\n");
} else
printf("The driver is not insured\n");
return 0;
}
I am aware that I can use else if (sex == F && age > 25)
instead of nesting the last if command but I want to know what happens when I write it this way and why does the out put show 'The driver is not insured.'