# 查询自动售货机中的商品价格

## 二、所需技能

• if 、switch 语句
• for 循环
• 数据类型转换

## 三、代码实现

    int choice,i;
double price;
for(i=1;i<=5;i++){
//以下5行显示菜单
printf("[1]Select crisps\n");  //查询薯片价格
printf("[2]Select popcorn\n");  //查询爆米花价格
printf("[3]Select chocolate\n");  //查询巧克力价格
printf("[4]Select cola\n");  //查询可乐价格
printf("[0]exit\n");  //退出查询
printf("Enter choice:");
scanf("%d",&choice);

if(choice == 0)  //如果输入为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.0;break;
default:price = 0.0;break;

}

printf("price = %0.1f\n",price);
}
printf("Thank you\n");
return 0;

posted @ 2017-04-01 19:39  Zoctopus_Zhang  阅读(...)  评论(...编辑  收藏
// function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; \$("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);