c++华氏或摄氏转换器
c++ Fahrenheit or Celsius converter
嗨,只是想知道为什么这是不工作,截至目前,它只打印出华氏温度,无论我选择c或f,请帮助
#include <iostream>
using namespace std;
int main()
{
char unit;
float degrees = 0.0;
float Farenheit, Celsius;
cout << "Enter the temperature unit you are currently in (f or c): ";
cin >> unit;
cout << "Enter the temperature in degrees: ";
cin >> degrees;
if ( unit == 'c' || 'C')
{
Farenheit = (degrees - 32) / 9 * 5.0;
cout << "The degrees in Farenheit are: " << Farenheit << endl;
}
else if ( unit == 'f' || 'F')
{
Celsius = (degrees - 32) * 5.0/9;
cout << "The degrees in Celsius is: " << Celsius << endl;
}
return 0;
}
这样可能效果更好:
if ( unit == 'c' || unit == 'C')
相关文章:
- 转换器练习:跳过 if 语句和 if 语句
- 使用转换器提升 Python 问题 - 静态链接
- 我写的 ASCII 到二进制转换器C++向后显示二进制,如何使其正确显示?
- 十进制到二进制转换器 c++
- 用于 boost::p roperty_tree 的通用枚举转换器
- 为什么我的C++基转换器中出现分段错误?
- 将字节数组转换为对象C++ |C++中的 C# 位转换器
- 英语到摩尔斯电码转换器
- 我用c++做了一个转换器,把英里转换成公里,把公里转换成英里,把赛尔修斯转换成法赫伦海特,把法赫伦海特转换成赛尔修斯
- 使用 Json 转换器反序列化 WCF 服务中的C++字符串
- 十进制,包括负到 32 位二进制转换器
- 标准::映射转换器模板
- 英里到千克转换器练习的小语法错误
- 句子转换器在存在新行的情况下不起作用
- 在C Windows程序中获取A/D转换器示例程序
- ROS中未定义的参考误差到OpenCV图像转换器
- 表达式到C++类类型转换器/类型转换
- 这里怎么了?单位转换器
- 华氏度到摄氏转换器C
- 如何理解 c++ 中的 MNIST 二进制转换器?