我可以缩短这个 if 语句吗?
Can I shorten this if statement?
这个if
-语句当前将变量与静态数字进行比较,如果它们相等,则为settime7
变量提供一个十六进制,用于将时间发送到单位。
有没有办法缩短这个if
语句:
if(timeM == 0){
settime7 = 0x00;
}
else if(timeM == 1){
settime7 = 0x01;
}
else if(timeM == 2){
settime7 = 0x02;
}
else if(timeM == 3){
settime7 = 0x03;
}
// ...and so on to timeM == 60 and settime = 0x3C.
只需分配变量:
settime7 = timeM;
无论您将整数写为十进制还是十六进制,对于存储的整数都无关紧要。
如果我很清楚你想要的话
...
else if(timeM == 60){
settime7 = 0x60;
}
然后:
settime7 = (timeM / 10) * 16 + (timeM % 10)
相关文章:
- 我的简单if-else语句是如何无法访问的代码
- Insert函数不适用于2 if语句C++
- If语句未被求值C++
- C++嵌套if语句,基本货币交换
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 是否可以使用if constexpr删除控制流语句
- 我似乎对if/else的基本语句有问题:/
- If语句在c++中被忽略
- 比较if语句中的数组值和int值
- 以在Qt中的IF语句中设置时间延迟
- Craps游戏问题,忽略if语句
- c++:定义if语句中的模板
- C++嵌套的 If 语句中,它无法按预期工作
- 如果中的多个语句是否与多个 if 相同?
- C++ If/Else 语句被跳过
- 使用语句if时逻辑的问题
- 如何添加语句if-else
- 如何将语句if(isalpha(c))从c++转换为MIPS ?
- 在if语句if C++中创建对象时出现作用域问题
- if语句-if/else和参数放置C++