猜价格小练习

题目:
这里写图片描述

代码:

#include <iostream>

using namespace std;

int main()
{

    int price = 5000;
    int price_guss;
    int i;
    for(i = 1; i<= 5; i++)
    {
        cout << "神秘商品的价格是(第" << i << "次): " ;
        cin >> price_guss;
        if(price_guss == price)
        {
            cout << "恭喜您猜对了!" << endl;
            switch(i)
            {
                case 1:
                    cout << "恭喜您中了头奖:iPhone8S Plus Plus 土豪金一部" << endl;
                    break;
                case 2:
                case 3:
                    cout << "恭喜您中了小米移动电源" << endl;
                    break;
                default:
                    cout << "恭喜您中了VR眼镜" << endl;
                    break;
            }
            break;
        }
        else
        {
            if(price_guss > price)
            {
                cout << "您猜测的价格大了!" << endl;
            }
            else
            {
                cout << "您猜测的价格小了!" << endl;
            }
        }
    }
    if(i > 5)
    {
        cout << "5次机会已经用完,下次再接再厉!" << endl;

    }
    return 0;
 }

猜你喜欢

转载自blog.csdn.net/ghyyys/article/details/81949170