第三章例3-8

/* 查询自动售货机中商品的价格 */
#include<stdio.h>
int main(void)
{
    int choice,i;
    double price;

    for(i=1;i<=5;i++){
        printf("[1]Select crisps\n");
        printf("[2]Select popcorn\n");
        printf("[3]Select chocolate\n");
        printf("[4]Select cola\n");
        printf("[0]Select exit\n");

        printf("Enter choice:");
        scanf_s("%d",&choice);
        
        if(choice==0)
            break;
        switch(choice){
            case 1:price=3.0;break;
            case 2:price=4.0;break;
            case 3:price=3.5;break;
            case 4:price=0.0;break;
            default:price=0.0;break;
        }

        printf("price=%0.1f\n",price);
    }
        printf("Thanks\n");

        return 0;
    }
                 

posted @ 2013-10-04 23:49  刘睿1994  阅读(99)  评论(0编辑  收藏  举报