3-8

#include<stdio.h>
int main(void)
{
    int choice,i;
    double price;
    for(i=1;i<=5;i++){
    printf("[1]Select crisps
");
    printf("[2]Select popcorn
");
    printf("[3]Select chocolate
");
    printf("[4]Select cola
");
    printf("[0]exit
");
    printf("Enter choice:");
    scanf_s("%d",&choice);
    if(choice==0)
    break;
    switch(choice){
    case 1:price=3.0;break;
    case 2:price=2.5;break;
    case 3:price=4.0;break;
    case 4:price=3.5;break;
    default:price=0.0;break;
    }
    printf("price=%0.1f
",price);
    }
    printf("Thanks
");
    return 0;
}

原文地址:https://www.cnblogs.com/zy1235/p/3355162.html