酷代码 AI
菜单
服务商

写出enter your name. alice hello alice, do you want to repeat this program? yes enter your name. bob hello bob, do you want to repeat this program? yes enter your name. charlie hello charlie, do you want to repeat this program? no goodbye, charlie! 的c++代码

以下是一个简单的 C++ 代码示例,实现了你描述的功能: ```cpp #include <iostream> #include <string> int main() { std::string name; std::cout << "enter your name." << std::endl; std::cin >> name; std::cout << "hello " << name << ", do you want to repeat this program?" << std::endl; std::string answer; std::cin >> answer; while (answer == "yes") { std::cout << "enter your name." << std::endl; std::cin >> name; std::cout << "hello " << name << ", do you want to repeat this program?" << std::endl; std::cin >> answer; } if (answer == "no") { std::cout << "goodbye, " << name << "!" << std::endl; } return 0; } ``` 这段代码首先提示用户输入名字,然后询问是否重复程序。如果回答是"yes",则再次执行输入名字和询问的过程。如果回答是"no",则输出再见的消息。 [2024-10-22 08:36:28 | AI写代码神器 | 267点数解答]

相关提问
发财导航,免费问AI
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]