c++ - 为什么我的代码没有被读取为 0 是有效响应?
问题描述
我在让用户按 0 输出字符串或输出小时数值的代码区域遇到问题。它只会执行后一个选项,我不知道为什么。
//Do you want the minutes converted into hours?
if ((a != 0) && (a != 1)) {
cout << "That is not a valid answer. Please try again.";
}
else if (a = 0) { <----- My issue with the code is here.
cout << "Thank you for using the program";
}
else if (a = 1) { <----- My issue with the code
average_hours_per_day = average_minutes_per_day/hour;
cout << average_hours_per_day;
}
解决方案
推荐阅读
- react-360 - react-vr 集成了一个按钮用于进入 vr 模式
- c++ - std::vector::push_back() 不能在 MSVC 上为具有已删除移动构造函数的对象编译
- java - Spring Data Neo4j - findById 方法在升级到 Spring Boot 2 后抛出无效查询异常
- javascript - 尝试构建项目抛出:需要回调函数但得到 [object Promise]?
- knockout.js - KnockoutJS 在 ko.applybinding 之后没有更新 ui
- string - 如何将文本相对于一个字符分成几个部分
- jenkins - 如何停止 Jenkins 轮询 SVN 源代码控制?
- cordova - 在 Ionic 3 的 VLC 播放器上添加叠加元素
- .net - .Net Core JwtBearer 中间件使用 Amazon Cognito
- sorting - 在权重约束下最大化整数条目的总和