1017. 價格查詢
題目描述
程式設計實作以下功能:查詢水果的單價。有4種水果,蘋果(apples)、梨(pears)、桔子(oranges)和葡萄(grapes),單價分别是3.00元/公斤,2.50元/公斤,4.10元/公斤和10.20元/公斤。
運作程式後,首先在螢幕上顯示以下菜單(編号和選項)(見樣例)。
當使用者輸入編号1~4,顯示相應水果的單價(保留1位小數);輸入0,退出查詢;輸入其他編号,顯示價格為0。
輸入
輸入一個整數。
輸出
輸出對應的結果。
樣例輸入
3
樣例輸出
[1] apples
[2] pears
[3] oranges
[4] grapes
[0] Exit
price=4.1
資料範圍限制
C++代碼
#include <iostream>
using namespace std;
int main()
{
int choice;
cout << "[1] apples" << endl;
cout << "[2] pears" << endl;
cout << "[3] oranges" << endl;
cout << "[4] grapes" << endl;
cout << "[0] Exit" << endl;
cin >> choice;
switch(choice)
{
case 1: cout << "price=3.0" << endl; break;
case 2: cout << "price=2.5" << endl; break;
case 3: cout << "price=4.1" << endl; break;
case 4: cout << "price=10.2" << endl; break;
case 0: cout << endl; break;
default: cout << "price=0" << endl; break;;
}
return 0;
}