买东西打折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的用法