Main  /  Edit  /  History  /   /  Users Area

CppCMS — High Performance C++ Web Framework

<h1>include <iostream></h1> <h1>include <cstdlib></h1> <h1>include <ctime></h1>

using namespace std;

int main() { // 初始化随机数生成器 srand(time(0));

// 生成1-100之间的随机数
int secretNumber = rand() % 100 + 1;
int guess = 0;
int attempts = 0;

cout << "欢迎来到猜数字游戏!" << endl;
cout << "我已经想好了一个1到100之间的数字,你能猜出来吗?" << endl;

while (guess != secretNumber) {
    cout << "请输入你的猜测: ";
    cin >> guess;
    attempts++;

    if (guess > secretNumber) {
        cout << "太大了!再试试。" << endl;
    } else if (guess < secretNumber) {
        cout << "太小了!再试试。" << endl;
    }
}

cout << "恭喜你!你在" << attempts << "次尝试后猜对了!" << endl;
cout << "游戏结束,谢谢参与!" << endl;

return 0;

}

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0