13. 条件查询3

创建日期:2024-07-14
更新日期:2025-02-01

ifelseif.cpp

#include <iostream>

const int Fave = 27;
int main()
{
    using namespace std;
    int n;

    cout << "Enter a number in the range 1-100 to find ";
    cout << "my favorite number: ";
    do
    {
        cin >> n;
        if (n < Fave)
        {
            cout << "Too low -- guess again: ";
        }
        else if (n > Fave)
        {
            cout << "Too high -- guess again: ";
        }
        else
        {
            cout << Fave << " is right!\n";
        }

    } while (n != Fave);
}