Monday, 4 March 2019

write a program using switch and if statements to coma customerpute the net amount to be paid by customer

#include<stdio.h>
main()
{
    float a;
    char ch;
    printf("Enter amount: ");
    scanf("%f",&a);
    printf("Enter item name for Mill 'm' for Handloom 'h': ");
    scanf("%s",&ch);
    if(a>0&&a<=100)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount =%.2f",a);
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a-=(a*0.05)));
                break;
            }
        }
    }
    else if(a>=101&&a<=200)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount = %.2f",(a-=(a*0.05)));
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a-=(a*0.075)));
                break;
            }
        }
    }
    else if(a>=201&&a<=300)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount = %.2f",(a-=(a*0.075)));
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a-=(a*0.1)));
                break;
            }
        }
    }
    else if(a>300)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount = %.2f",(a=(a*0.1)));
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a=(a*0.15)));
                break;
            }
        }
    }
}

No comments:

Post a Comment