c++ - 用户输入/如果语句保持返回而不是继续
问题描述
我正在尝试运行此代码,当我输入“nfc123”的用户输入时,它会打印 Door Unlocked 虽然它返回到开始并希望我再次解锁门。我希望它继续并询问我是否想锁门。
#include <string>
#include <iostream>
int main( int, char ** )
{
std::string input;
while( true )
{
std::cout << "Unlock Door Code: " << std::endl;
std::cin >> input;
if( input == "nfc123" )
{
std::cout << "Door Unlocked" << std::endl;
continue;
}
else if( input == "end" )
{
break;
}
else
{
std::cout << "Wrong Code: " << input << std::endl;
}
}
std::string input2;
while( true )
{
std::cout << "Lock Door Code: " << std::endl;
std::cin >> input2;
if( input2 == "nfc123" )
{
std::cout << "Door Locked" << std::endl;
}
else if( input2 == "end" )
{
break;
}
else
{
std::cout << "Wrong Code: " << input2 << std::endl;
}
}
return 0;
}
解决方案
推荐阅读
- django - 有效地从 ManyToManyField 检索并添加到 ManyToManyField
- tensorflow - 张量流中具有分类分布的集成网络
- while-loop - 这两个循环有什么区别?
- xpath - html.fromstring() 和 etree.fromstring() 生成的树的差异
- java - 一维排序数组,但 array[i+1] 总是打印索引为零的元素
- excel - 在 VBA 中使用 .NET HashTable 返回类型
- swiftui - SwiftUI @State var 初始化问题
- python - discord.py-rewrite - 如何获得会员的加入排名?
- amazon-web-services - Gitlab CI:生成 JavaScript 包失败。在构建期间 - GitLab CI + AWS s3、cloudfront、gatsby.js
- python - 在 HTML 上运行 Python 脚本