CCF NOI1017. 价格查询

版权声明:代码属于原创,转载请联系作者并注明出处。 https://blog.csdn.net/weixin_43379056/article/details/84889938

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;
}

猜你喜欢

转载自blog.csdn.net/weixin_43379056/article/details/84889938
今日推荐