Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why I am not able to enter my "condition" in my program ??

+1 vote
asked May 19, 2021 by Burhan Hariyana (170 points)
{
    int age ;
    char gender , condition ;
    printf("Enter the age of the customer :");
    scanf("%d",&age);

    printf("What is the gender of the customer :");
    scanf(" %c",&gender);

    printf("What is the condition of the customer :");
    scanf(" %c",&condition);

    switch (age,gender,condition)
    {
    case '25<age<35 , male , excellent'   :
        {
            printf("The premium is Rs 4 per thousand and premium cannot exceed Rs 2 lakh\n");
            break ;
        }
     case  '25<age<35 , female , excellent' :
        {
                printf("The premium is Rs 4 per thousand and premium cannot exceed Rs 1 lakh\n");
            break ;
        }
     case '25<age<35 , male , poor' :
        {
                    printf("The premium is Rs 6 per thousand and premium cannot exceed Rs 10000\n");
            break ;

        }
     default :
        printf("The person is not insured\n");

    }

    return 0;
}

1 Answer

0 votes
answered Nov 16, 2021 by him32 (140 points)
You can't use switch case as switch doesn't support condition checking. You have to change ur program into if else. I am converting this program in if form

#include <stdio.h>

int main ()

{

  int age;

  char gender, condition;

  printf ("Enter the age of the customer :");

  scanf ("%d", &age);

  printf("What is the gender of the customer ?\n Press M for male and F for female");

  scanf (" %c", &gender);

  printf("What is the condition of the customer : \n 1)Press A for Best \n 2)Press B for Better \n3)Press C for Good \n4)Press D for Poor");

  scanf (" %c", &condition);

  if (((age >= 25) && (age < 35)) && (gender == 'M' || gender == 'm')

      && (condition == 'A'))

    {

      printf("The premium is Rs 4 per thousand and premium cannot exceed Rs 2 lakh\n");

    }

  else if (((age >= 25) && (age < 35)) && (gender == 'F' || gender == 'f')

   && (condition == 'A'))

    {

      printf("The premium is Rs 4 per thousand and premium cannot exceed Rs 1 lakh\n");

    }

  else if (((age >= 25) && (age < 35)) && (gender == 'M' || gender == 'm')

   && (condition == 'D'))

    {

      printf("The premium is Rs 6 per thousand and premium cannot exceed Rs 10000\n");

    }

  else

    {

      printf ("Person not insured");

    }

  return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...