用 C++ 写了个小游戏
#include <iostream>#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int num, guess, tries = 0;
srand(time(0));
num = rand() % 100 + 1;
do {
cout << "Enter a number between 1 and 100 : ";
std::cin >> guess;
tries++;
if (guess > num)
std::cout << "Too high! Try again.\n\n";
else if (guess < num)
std::cout << "Too low! Try again.\n\n";
else
std::cout << "Correct! You guessed it in " << tries << " tries!\n";
} while (guess != num);
return 0;
} 想起当年上学时的《数据结构》课
页:
[1]