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

📄 guessinggame.cpp

📁 一个好玩的猜谜游戏
💻 CPP
字号:
#include <string>
#include <iostream>
#include <time.h>
#include "prompt.h"
using namespace std;

const int MAX_GUESS_RANGE = 100;
const int MAX_NUM_GUESSES = 10;

int main()
{
	int iNumber, iGuess;
	int i;

	srand(time(NULL));

	do {
		iNumber = rand() % MAX_GUESS_RANGE;
		cout << "Try to guess my number, which is between 0 and " << MAX_GUESS_RANGE << endl;
		cout << "You have " << MAX_NUM_GUESSES << " to figure out the number" << endl;

		for (i = 1; i <= MAX_NUM_GUESSES; i++) {
			cout << i << ". What's your guess: ";
			cin >> iGuess;

			if (iGuess == iNumber) {
				cout << "You're right.  The number is " << iGuess << endl;
				break;
			} else if (iGuess > iNumber) {
				cout << "You're guess is too high." << endl;
			} else {
				cout << "You're guess is too low." << endl;
			}
		}

		if (i > MAX_NUM_GUESSES) {
			cout << "You lose.  The number was " << iNumber << endl;
		}
	} while (PromptYesNo("Do you want to play again?"));


 	return 0;
}

⌨️ 快捷键说明

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