c++实现显示用户注册登录小游戏,小游戏为一个单词然后消失后填写该单词,相同则正确不同则错误
时间: 2024-03-15 21:42:51 浏览: 26
好的,这是一个比较简单的小游戏,可以用c++实现。下面是一个简单的示例代码,供参考:
```
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
// 随机生成一个单词
string word_list[] = {"apple", "banana", "orange", "pear", "grape", "watermelon"};
srand(time(NULL));
int index = rand() % 6;
string word = word_list[index];
// 显示单词
cout << "请记住下面的单词:" << endl;
cout << word << endl;
// 清屏
system("pause");
system("cls");
// 提示用户输入单词
string input;
cout << "请输入上面显示的单词:" << endl;
cin >> input;
// 比较输入的单词和随机生成的单词
if (input == word)
{
cout << "恭喜你,输入正确!" << endl;
}
else
{
cout << "很遗憾,输入错误!" << endl;
}
return 0;
}
```
这个示例代码中,首先随机生成一个单词,然后显示给用户,等待用户记住后清屏。然后提示用户输入单词,最后比较用户输入的单词和随机生成的单词是否相同,给出相应的提示。