0
#include <stdio.h>


int main()
{
    char membershiptype;
        int purchase;
        //float monthly_reward;
    // enter membership type;
    printf("membership type: ");
    scanf("%c", &membershiptype);
        printf("Standard = S , Plus = P , Premium = A");

switch(membershiptype)
    {


        case 'S':

                      printf("\n\nEnter the total monthly purchase :RM");
                      scanf("%d", &purchase);
                      if (purchase < 75)
                      printf("\nMonthly Reward :RM%.0f \n\n",(purchase*0.05)); 
                      else if (purchase > 75 && purchase < 149.99)
                      printf("\nMonthly Reward :RM%.0f \n\n",(purchase*0.075));
                      else if (purchase > 150)
                      printf("\nMonthly Reward :RM%.0f \n\n",(purchase*10.0));

              break;

                case 'P':

                      printf("\n\nEnter the total monthly purchase :RM");
                      scanf("%d", &purchase);
                      if (purchase < 150)
                      printf("\nMonthly Reward :RM%.0f \n\n",(purchase*0.06)); 
                      else if (purchase > 150)
                      printf("\nMonthly Reward :RM%.0f \n\n",(purchase*13.0));

                     break;

            case 'A':

                     printf("\n\nEnter the total monthly purchase :RM");
                     scanf("%d", &purchase);
                     if (purchase < 200)
                     printf("\nMonthly Reward :RM%.0f \n\n",(purchase*0.04));
                     else if  (purchase > 200)
                     printf("\nMonthly Reward :RM%.0f \n\n",(purchase*0.15));

                    break;

        default:
            printf("Invalid Membership");
    } // end of switch
}
2
Contributors
1
Reply
18
Views
2 Years
Discussion Span
Last Post by Banfa
0

You could simplify this by only putting the calculation of the monthly reward in the switch statement, i.e.

    double reward;

    /* printf/scanf statements to get membership and monthly purchase */

    switch(membershiptype)
    {
        /* Cases to calculate the monthly reward and store in reward */
    }

    /* printf statements to output final messages and the achieved monthly reward */

Effectively separate out the logic from the user interface. This is alwaysa good thing to learn to do because in real life the UI often changes while the logic stays the same so you don't want your logic code mixed up with your UI code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.