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 :

5 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
  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


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!!!