c++输出转换错误
C++ Output Conversion Error
我应该做一个代码,从英尺和英寸转换到米和厘米。但是当我运行我的代码时,我没有得到我应该得到的。例如,我输入1英尺和0厘米。我应该得到0.3048米和0厘米但我得到的是1米和0厘米。的帮助!
#include <iostream>
using namespace std;
void getLength(double& input1, double& input2);
void convert(double& variable1, double& variable2);
void showLengths(double output1, double output2);
int main()
{
double feet, inches;
char ans;
do
{
getLength(feet, inches);
convert(feet, inches);
showLengths(feet, inches);
cout << "Would you like to go again? (y/n)" << endl;
cin >> ans;
cout << endl;
} while (ans == 'y' || ans == 'Y');
}
void getLength(double& input1, double& input2)
{
cout << "What are the lengths in feet and inches? " << endl;
cin >> input1 >> input2;
cout << input1 << " feet and " << input2 << " inches is converted to ";
}
void convert (double& variable1, double& variable2)
{
double meters = 0.3048, centimeters = 2.54;
meters *= variable1;
centimeters *= variable2;
}
void showLengths (double output1, double output2)
{
cout << output1 << " meter(s) and " << output2 << " centimeter(s)" << endl;
}
任何帮助都是感激的。谢谢!
meters *= variable1;
centimeters *= variable2;
应该variable1 *= meters;
variable2 *= centimeters;
上一条评论说:你没有将产品分配给你通过引用传递的变量(variable1
和variable2
),所以这些值不会从你的原始输入1和0改变。
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- C++使用params创建线程函数会导致转换错误
- 在混合代码库中将C转换为C++时出现许多包含错误
- 为什么g++在未执行的代码处标记强制转换错误
- 错误:从"int"到枚举c++的转换无效
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- 从标准::未来<void>到非标量标准::未来<bool>引发的错误转换
- 使用宏的错误转换
- 在 opencv 中使用 Color_YUV2BGR 从 YUV 到 BGR 的错误转换
- 无法通过此操作,因为类型的错误转换
- PyQt5:使用自定义信号时 int 对象的错误转换
- 从长途错误转换
- C 错误:转换为非量表类型
- C 错误:转换为执行字符集
- 使用SOCI从PostgreSQL数据库获取数据时发生错误转换
- 分段错误C++转换问题
- 在ARM上的Qt中从双精度到QString的错误转换
- C++浮点转换为Python浮点错误转换
- 错误:转换为非标量类型