⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pr07005.cpp

📁 c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出版社的光盘
💻 CPP
字号:
////////////////////////////////////////
// File Name: pr07005.cpp
////////////////////////////////////////
#include <iostream>
#include <cstdlib>
#include <ctime>

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    std::srand(time(0));
    char ans;

    // Loop until the user is done.
    do
    {
        // Choose a secret number.
        int fav = std::rand() % 32;

        // Loop until the user guesses the secret number.
        int num;
        do
        {
            std::cout << "Guess my secret number (0 - 32) ";
            std::cin >> num;

            // Report the status of the guess.
            std::cout << (num < fav ? "Too low"  :

                     num > fav ? "Too high" :
                                 "Right") << std::endl;
        }
        while (num != fav);

        std::cout << "Go again? (y/n) ";
        std::cin >> ans;
    }
    while (ans == 'y');

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -