1072: 显示水果的价格
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
以下 4 种水果的单价分别是3.00 元/公斤,2.50 元/公斤,4.10 元/公斤,10.20 元/公斤。
[1] apples
[2] pears
[3] oranges
[4] grapes
输入水果的编号,输出该水果的单价(保留2 位小数)。如果输入不正确的编号,显示单价为0.00。
Input
见sample
Output
见sample
Sample Input
1
3
Sample Output
price=4.10
代码
#include<stdio.h>
int main()
{
int i,choice,r;
double price;
scanf("%d",&r);
for(i=1;i<=r;i++){
scanf("%d",&choice);
switch(choice){
case 1:price=3.00;break;
case 2:price=2.50;break;
case 3:price=4.10;break;
case 4:price=10.20;break;
default:price=0.00;break;
}
printf("price=%.2lf\n",price);
}
return 0;
}