|
注册免广告
您需要 登录 才可以下载或查看,没有账号?注册
×
- #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;
- }
复制代码 |
|