+ 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();}

16th Mar 2018, 9:17 AM
Nitesh Yadav
Nitesh Yadav - avatar
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(); }
2nd Apr 2018, 1:10 AM
Emma
+ 10
Use else if instead of if else: if(..){ // } else if(...){ // } else if(..){ // } else{ // }
16th Mar 2018, 9:20 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 4
use "else if" instead of "if else"
22nd Mar 2018, 1:58 PM
Md Ashraful Alam
Md Ashraful Alam - avatar