Click here to Skip to main content
14,696,341 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
def getDescription (type_plan ):

    string = ""

    # Check the plan type GENERAL
    if type_plan[0] == 'A':

        # Check the type of plan
        if type_plan == "A1":
            string += "Annual Claim Limit 100.000\n"

        # Check the type of plan
        elif type_plan == "A2":
            string += "Lifetime Claim Limit 500000\n"

        string += "Room Charges 150/day\n"
        string += "Intensive Care Unit (ICU) Charges 300/day\n"
        string += "Hospital Supplies and Services : As charged. Subject to approval by EZMediLife. Surgical Fees\n"

    # Check the plan type GENERAL
    elif type_plan[0] == 'B':

        # Check the type of plan
        if type_plan == "B1":
            string += "Annual Claim Limit 200000\n"

        # Check the type of plan
        elif type_plan == "B2":
            string += "Lifetime Claim Limit 1000000\n"

        string += "Room Charges 200/day\n"
        string += "Intensive Care Unit (ICU) Charges 500/day\n"
        string += "Hospital Supplies and Services : As charged. Subject to approval by EZMediLife. Surgical Fees\n"

    # Check the plan type GENERAL
    elif type_plan[0] == 'C':

        if type_plan == "C1":
            string += "Annual Claim Limit 300000\n"
        elif type_plan == "C2":
            string += "Lifetime Claim Limit 2000000\n"
        string += "Room Charges 300/day\n"
        string += "Intensive Care Unit (ICU) Charges 900/day\n"
        string += "Hospital Supplies and Services : As charged. Subject to approval by EZMediLife. Surgical Fees\n"

    return string


What I have tried:

i tried the requirements to write in python. i dont know much about C language.
Posted
Updated 12-Oct-20 2:54am
v2

Something like the following code should do the trick, provided you complete it (just plan 'A' is covered') and make it robust.

#include<stdio.h>

int get_description(const char type_plan[], const char ** description, const char ** claim_limit )
{
  int result = 0; // 0 is 'success' , non-zero is 'failure' 

  switch (type_plan[0])
  {
  case 'A':
    *description = "Room Charges 150/day\nIntensive Care Unit (ICU) Charges 300/day\nHospital Supplies and Services : As charged. Subject to approval by EZMediLife. Surgical Fees\n";
    switch(type_plan[1])
    {
    case '1':
      *claim_limit = "Annual Claim Limit 100.000\n";
      break;

    case '2':
      *claim_limit = "Lifetime Claim Limit 500000\n";
      break;

    default:
      result = -1;
      break;
    }

    break;
  case 'B':
    //...

  case 'C':
    //...

  default:
    result = -1;
    break;
  }

 return result;

}


int main()
{
  const char * plane[]  = { "A1", "K3", "A2" }; -- test planes

  for ( size_t n=0; n<sizeof(plane) / sizeof(plane[0]); ++n)
  {
    const char * description, * claim_limit;
    if ( get_description( plane[n], &description, &claim_limit) == 0)
    {
      printf("plane %s: %s%s", plane[n], claim_limit, description);
    }
    else
    {
      printf("unknown plane %s\n", plane[n]);
    }
    printf("\n");
  }
  return 0;
}
   
Comments
Shao Voon Wong 13-Oct-20 1:02am
   
My 5!
CPallini 13-Oct-20 1:59am
   
Thank you very much!
This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.
   
You need to learn C from some tutorial like Learn C.

you need to understand some differences to Python:
- C is a different language, so you have other keywords, like if and else
- C has parenthis rules form curly braces and non-curly braces
- C has no classes, so you need to recode the string handling complete
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900