Program To Calculate Driver insurance using if-else statement

A company insures its drivers in the following cases:
- If the driver is married.
- If the driver is unmarried, male and above 30 years of age.
- If the driver is unmarried, female and above 25 years of age.

In all the other cases, the driver is not insured.
If the marital status, sex and age of the driver are the inputs,
write a program to determine whether the driver is insured or not.






#include
main()
{

char sex,ms;
int age;

printf ("Enter age, sex, marital status:");

scanf ("%d %c %c", &age, &sex, &ms);

if (ms=='M')

printf ("The driver is insured");
else
{
if (sex=='M')

{
if (age>30)
printf ("Driver is insured");

else
printf ("Driver is not insured");
}
else
{

if (age>25)
printf ("Driver is insured");
else
printf ("Driver is not insured");

}
}
}




Related Links :

14 comments:

  1. the result is not displaying the marital status of the driver

    ReplyDelete
  2. //can anyone tell me whats the error in my programme, i unable to enter sex//



    char sex,ms;
    int age;

    printf ("Enter age");
    scanf("%d", &age);
    printf("Enter Sex");
    scanf("%c", &sex);
    printf("\nEnter MS");
    scanf("%c", &ms);
    if (ms=='M')

    printf ("The driver is insured");
    else
    {
    if (sex=='M')

    {
    if (age>30)
    printf ("Driver is insured");

    else
    printf ("Driver is not insured");
    }
    else
    {

    if (age>25)
    printf ("Driver is insured");
    else
    printf ("Driver is not insured");
    getch();

    }
    }
    }

    ReplyDelete
    Replies
    1. check the the letter should be in capital

      Delete
    2. char is only one varible,key press one time but prog 2time read so this candition use getcher

      Delete
  3. Hello friend u hv to write getch(); before last closing braces .... now its work finely ...

    ReplyDelete
  4. i am unable to enter third input can anyone help?

    ReplyDelete
  5. #include
    #include
    void main()
    {

    char gender,ms;
    int age;
    clrscr();
    printf ("Enter age, gender, marital status:");

    scanf ("%d %c %c", &age, &gender, &ms);

    if (ms=='M')
    {

    printf ("The employee is insured");
    }
    else if (ms=='U' && gender=='M' && age>30)
    {
    printf ("employee is insured");
    }
    else if (ms=='U' && gender=='F' && age>25 )
    {
    printf ("employee is insured");
    }
    else
    {
    printf ("employee is not insured");
    }
    getch();
    }




    plz tell me whats wrong in this

    ReplyDelete
  6. #include
    int main()
    {
    char sex,marital_status;
    int age;
    printf("Enter age,sex and marital status\n");
    scanf("%d%c%c",&age,&sex,&marital_status);
    if((marital_status=='married')||(marital_status=='unmarried'&&sex=='male'&&age>30)||(marital_status=='unmarried'&&sex=='female'&&age>25))
    printf("Driver should be insured \n");
    else
    printf("Driver should not be insured \n");
    return 0;
    }

    please tell me why my program is not running.

    ReplyDelete
  7. #include
    void main()
    {
    char ms;
    int age,gen;
    printf("enterr the marrige status,gender,age(Male = 0, female = 1) = ");
    scanf("%c%d%d",&ms,&gen,&age);

    if(ms == 'M')
    {
    printf("driver should be insured\n");
    }
    else
    {
    if(gen== 0)

    {
    if(age>30)
    {
    printf("driver should be insured\n");
    }
    else
    {
    printf("driver should'nt be insured\n");
    }
    }
    else
    {
    if(age>25)
    {
    printf("driver should be insured\n");
    }
    else
    {
    printf("driver should'nt be insured\n");
    }
    }
    }
    }
    here you are facing problem because your are using integer before the char, but if you'll use char as input in starting then your problem will be solved, try it

    ReplyDelete
  8. This question is solved using Switch case ...

    ReplyDelete


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!