求两个温度之间的差
Finding the difference between two temperature
我有一个函数,应该找到两个温度之间的差异。首先,我打印出摄氏温度和大概华氏温度,然后我找到并打印出它们之间的差异。我的问题是,当我运行这个程序时,所有输出的差值都是58。
它应该打印出如下内容:
C----AF----Diff
1----32----31
2----34----32
等。我代码:
void calDiff(int& cel, int& appFar, int diff){
while(cel!= 101){
diff = appFar - cel;
cout << diff << endl;
cel++;
appFar++;
}
}
- 你需要一个函数把摄氏度转换成华氏度。
- 如果您不想更改
cel
和appFar
,则删除参考&
。
int cel2far(int cel)
{
// convert cel to far and return approx. far
}
void calDiff(int cel, int appFar, int diff)
{
while(cel!= 101){
diff = appFar - cel;
cout << diff << endl;
cel++;
appFar = cel2far(cel);
}
}
每次循环都将摄氏度和华氏温度分别增加1,因此每次的差值都是相同的。仅仅因为你通过参考传递温度并不意味着当你改变温度时它会重新计算华氏温度。您应该将摄氏度加1,重新计算华氏度,然后计算差值。
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 在cuda线程之间共享大量常量数据
- 在c代码之间共享数据的最佳方式
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 大小相等但成员数量不同的结构之间的性能差异
- 类与私有变量的其他类之间的线程安全性
- 如何在cpp文件之间切换窗口?在Qt中
- 线程之间的布尔停止信号
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 构造函数和转换运算符之间的重载解析
- 求两个温度之间的差