+ 6
what is the error in this c program
main() { int a; char ms, sex; printf("Enter the age , martial status in y and n and sex in f and m:"); scanf("%d%c%c",&a,&ms,&sex); if(ms=='y') printf("insured"); if else(ms=='n'&&sex=='m'&&a>30) printf("insured"); if else(ms=='n'&&sex=='f'&&a>25) printf("insured"); else printf("not insured"); getch();}
3 Réponses
+ 3
It's also better to format your code so it's easier to read:
int main()
{
int a;
char ms, sex;
printf("Enter the age , martial status in y and n and sex in f and m:");
scanf("%d%c%c",&a,&ms,&sex);
if (ms == 'y')
{
printf("insured");
}
else if (ms == 'n' && sex == 'm' && a > 30)
{
printf("insured");
}
else if (ms == 'n' && sex == 'f' && a > 25)
{
printf("insured");
}
else
{
printf("not insured");
}
getch();
}
+ 10
Use else if instead of if else:
if(..){
//
}
else if(...){
//
}
else if(..){
//
}
else{
//
}
+ 4
use "else if" instead of "if else"