pxxfxxxxx

导航

买东西打折switch

#include <stdio.h>
int main()
{
    int sum;
    printf("input the shopping sum:");
    scanf("%d",&sum);
    printf("%d",sum);
    switch(sum/500)
    {
        case 0:
            printf("You should pay %.2lf.\n",sum);
            break;
        case 1:
            printf("You should pay %.2lf.\n",sum*0.95);
            break;
        case 2:
            printf("You should pay %.2lf.\n",sum*0.9);
            break;
        case 3:
            printf("You should pay %.2lf.\n",sum*0.85);
            break;
        default:
            printf("You should pay %.2lf.\n",sum*0.8);
            break;
    }
    return 0;
}

注意switch的用法

posted on 2019-03-29 21:43  pxxfxxxxx  阅读(220)  评论(0编辑  收藏  举报