- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我的程序可以编译,但我遇到了几个问题。我的第一个 cout
语句要求 e/E
结束工作,但在我的第二个 while 循环中我声明 (+ || - || * ||/)
不会运行。 +/-/*//
返回“操作类型无效”。你们能帮我看看我的错误吗?
第一个哨兵循环,只是学习循环:
#include <iostream>
using namespace std;
int main()
{
int numOne;
int numTwo;
int result;
string operation;
cout << "Please enter what operation you'd like to perform or e/E to end program: ";
cin >> operation;
while (operation == "e" || "E")
{
cout << "Operation type invalid." << endl;
cout << "Please enter what operation you'd like to perform or e/E to end program: ";
cin >> operation;
}
while (operation == "+" || operation == "-" || operation == "*" || operation == "/")
{
cout << "Please enter integer one: " << endl;
cin >> numOne;
cout << "Please enter integer two: " << endl;
cin >> numTwo;
if (operation == "+")
{
result = numOne + numTwo;
cout << "The numbers you entered were " << numOne << "," << numTwo << endl;
cout << "The operation you chose was " << operation << "." << endl;
cout << "The operations result is " << result << "." << endl;
cout << "Your equation was: " << numOne << " " << operation << " " << numTwo << " = " << result << ".";
}
else if (operation == "-")
{
result = numOne - numTwo;
cout << "The numbers you entered were " << numOne << "," << numTwo << endl;
cout << "The operation you chose was " << operation << "." << endl;
cout << "The operations result is " << result << "." << endl;
cout << "Your equation was: " << numOne << " " << operation << " " << numTwo << " = " << result << ".";
}
else if (operation == "*")
{
result = numOne * numTwo;
cout << "The numbers you entered were " << numOne << "," << numTwo << endl;
cout << "The operation you chose was " << operation << "." << endl;
cout << "The operations result is " << result << endl;
cout << "Your equation was: " << numOne << " " << operation << " " << numTwo << " = " << result << ".";
}
else if (operation == "/")
{
if (numTwo == 0)
{
cout << "You cannot divide by zero!" << endl;
}
else
{
result = numOne / numTwo;
cout << "The numbers you entered were " << numOne << "," << numTwo << endl;
cout << "The operation you chose was " << operation << "." << endl;
cout << "The operations result is " << result << endl;
cout << "Your equation was: " << numOne << " " << operation << " " << numTwo << " = " << result << ".";
}
}
}
return 0;
}
最佳答案
while (operation == "e" || "E")
这里你比较的是两个条件之一:
操作
== "e"
吗?"E"
是一个有效的指针吗?第二个条件是您的问题:"E"
当然是一个有效指针,因此该条件将始终为 true
。总是。请注意,在第二种情况下,您没有将 operation
与 "E"
进行比较。
你永远被困在这里:
while (operation == "e" || "E")
{
cout << "Operation type invalid." << endl;
cout << "Please enter what operation you'd like to perform or e/E to end program: ";
cin >> operation;
}
您只需要:
while (operation == "e" || operation == "E")
这可能只是一个打字错误或疏忽。
关于c++ - 哨兵循环不会运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36539863/
我正在研究用 C++ 编写的 Python 扩展模块。 根据 Python documentation模块方法表应该这样写: static PyMethodDef SpamMethods[] = {
我需要用redis搭建一个开发环境。它需要哨兵,以复制我们在生产中的行为(因为我们的客户端应用程序使用 JedisSentinelPool 进行连接)。 不幸的是我只有一台主机可用。即使只有一个实例,
单机配置启动 Redis安装 下载地址: http://redis.io/download 安装步骤: 1: 安装gcc编译器:yum install gcc 2:
基本上,我正在尝试设置一个 Redis-sentinel docker 实例,并希望从我的应用程序容器中进行调用。我正在运行的问题是 - redis-sentinel 容器链接到应用程序容器。 因此,
这段代码摘自 http://doc.qt.digia.com/qt/qhboxlayout.html#details是的,除了一些我不知道的魔法,充满了潜在的内存泄漏。 编辑:感谢 Nikos C.
我刚刚编辑了我之前的问题,并提供了更多详细信息(希望有人能够提供帮助)。 我有一个包含 1 个主服务器和 2 个从服务器的 Redis 集群。所有 3 个节点都由 Sentinel 管理。故障转移工作
我在主从设置中成功使用 Windows 版 Redis (2.6.8-pre2)。但是,我需要提供一些自动故障转移功能,看来 sentinel 是最受欢迎的选择。当我在 sentinel 模式下运行
我希望在 coreOS 集群上部署高可用性 Redis,我需要一个可以工作的 Redis Sentinel docker 镜像(即 Dockerfile)。我已经收集了足够的信息/专业知识来创建一个(
我试图让 1 个 redis master 和 2 个 redis 副本绑定(bind)到 Kubernetes 上的 3 Quorum Sentinel。我对 Kubernetes 很陌生。 我最初
我一直陷入代码的无限循环中。我必须做到这一点,这样您就可以使用哨兵“q”退出,但迭代次数不得超过 20 次。任何帮助将不胜感激,因为我只是编程新手。 #include using namespa
当 Redis Sentinel 通知事件时,它不会提供 Redis 主节点的名称。 配置摘录: # sentinel notification-script # # Call the speci
Redis 4.x 是否兼容使用 Sentinels 运行 TLS?我发现一些线程提到对 TLS 的支持将被添加到 3.2,但没有任何确认。 最佳答案 不,一般的 Redis,特别是 Sentinel
我正在尝试在一个 3 节点的 redis 集群中设置一个自动故障转移系统。我在每个节点上都安装了 redis-sentinel(就像这个人:http://www.symantec.com/connec
我一直在阅读有关使用 Redis 哨兵进行故障转移的内容。我打算有1个master+1个slave,如果master宕机超过1分钟,就把slave变成master。我知道这在 Sentinel 中是
我正在尝试为 Sentinal2 图像设置磁贴服务。 为了测试,我使用 S2A_MSIL2A_20171007T103021_N0205_R108_T32UMC_20171007T103241.SAF
我想用sentry来评估可能出现的错误、异常等 我尝试使用 KunstmaanSentryBundle,它非常适合捕获所有类型的错误,例如未定义的函数等,但我想用它自己的处理程序定义我自己的 Mono
1. 性能测试 - 【redis-benchmark】 //进入含有redis-benchmark执行文件的目录 // 解释:访问localhost:6379 模拟10个用户,每个用户请求10
我有一个集中式日志分析工作区,所有日志都会发送到该工作区,包括: 事件日志 网络日志 资源日志 系统指标 应用日志 应用洞察 现在,我想将此日志分析工作区用作哨兵工作区,这样我就不必连接各个资源。 这
我一直在 Ubuntu 10.10 上使用 Django 1.3 和 Python 2.6。我有 3 个问题。 我记得不久前我在 Windows 7 上使用 Django 时遇到过这个问题。不过,我还
我是一名优秀的程序员,十分优秀!