#include<stdio.h>
#include<conio.h>

void main()
{
    char gender,Mar_stat;
    int age;

    clrscr();
    printf("Enter your Marital Status "ma" or "um":\n");
    scanf("%c",&Mar_stat);
    if (Mar_stat == 'ma')
    {
        printf("Enter your Gender And Age :\n");
        scanf("%c %d",&gender,&age);
        if (gender=='M' && age >= 30)
        {
            printf("You are Insured");
        }
        else
        {
            printf("Sorry");
        }
        getch();
    }
}

What i am doing wrong in this program ,
i need a program to ask me If i am married, If married then ask my gender then age , if gender Male or Female and age minimum 30 or 25 respectively then printf("Your are insured ");
but it says nothing........

What am doing wrong

Try harder, your code has around 10 bugs and it does not compile because of line 10!

i change in line 10 from printf("Enter your Marital Status "ma" or "um":\n");

printf("Enter your Marital Status 'm' or 'u':\n");

and

in line 12 "ma" to "m"

but it still not work

it ask me for marital status but other two have some error...

How you write character m in C? How do you know if scanf succeeded or not? What will be next letter program reads in case of correct input?

ok i'm going to tell you what my program is actually...

input age

input Gender M or F

input Marital Status

-------> Married (if)

Male and age >30 then print you're insured
Female and age >25 then print you're insured

else not
-------> Un Married


Male and age >25 then print you're insured
Female and age >20 then print you're insured

else not print you are not Insured
----------------------------------------------

shouldn't i use char ms;

char ms='M' ;

I would suggest that you separate user input and leave it in the end. Prepere function that returns TRUE if person is insured based on gender and age parameters, FALSE otherwise. Gender could be easier to deal with as is_male boolean value. Call your function with many hard coded test values and print the results in main. When all tests pass do the user input part.

ok

one last question...


can i use a single char
example :

char ch;

in multiple cases ???

It is not worth it for only saving one byte. Use discribing full words with consistent form instead of single letters or ununderstandable abbreviations. Variable names are important for maintainability of the code.

void main() gives some folks ulcers!

commented: what a worthless comment! Meaningless to the person you meant it for. -4

I have done it!!!!!!!!!

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char gender;
char mar_stat;
int age=0;
printf("Enter your Marital Status Y/N and Gender M/F :\n");
scanf("%c %c",&mar_stat,&gender);
printf("Enter your Age :\n");
scanf("%d",&age);
if (mar_stat == 'Y' && gender == 'M' && age >= 30)

printf("You are Insured!");

else if (mar_stat == 'Y' && gender == 'F' && age >=25)

printf("You are Insured!");

else if (mar_stat == 'N' && gender == 'M' && age >=25)

printf("You are Insured!");

else if (mar_stat == 'N' && gender == 'F' && age >=20)

printf("You are Insured!");

else

printf("Sorry You are not Insured!");

getch();
}

Hi I am new this blog.
within if condition if you compare the variable with constant 'ma'. Its the semantic flaw. Out of range problem. If you compare with "m" or "ma" error will occur. Because double quoted characters are of string type and they cannot be compared with single character type. Just compare like this
(if mar_stat == 'm') then you will get the true condition for if statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.