如何在c++函数中移动变量



我正在参加社区大学的课程,我需要帮助将这个变量双和=mW/hW转换为相等的int股骨长度。当代码编译完成时,我需要它打印出来。mW和hW以毫米为单位,但在第二个函数中需要转换为厘米。有人能帮我吗

欢迎检查员,

头发分析:
请输入髓质宽度(单位:mm(:3
请输入整个头发宽度(单位为mm(:10

高度分析:请输入性别(0代表男性1代表女性:0
请输入股骨长度,单位为厘米:10
身高估计为84.582

这是我的代码

#include <iostream>
using namespace std;
void getHairtype()
{
double mW = 0;
double hW = 0;
double sum = mW / hW;

// Start of Get hair type fuction
cout << "Hair Analysis:" << endl;
cout << "Please enter the medulla with in mm" << endl;

//medulla Diameter
cin >> mW;
cout << mW << "mm" << endl;
cout << "Please enter the entire hair width in mm." << endl;
//entire hair
cin >> hW;
cout << hW << "mm" << endl;
// Ratio porptions
if (sum < .5)
{
cout << "1 : This is human hair" << endl;
}
else
{
cout << "0: This is animal hair" << endl;
}
return;
}
void getHumanHeiegth()
{
///Gender
int gender;
//femur length
int femurLength = 0;

double height = 69.089 + (2.238 * femurLength);
double heightI = 61.412 + (2.317 * femurLength);
cout << "Height Analysis:" << endl;
cout << "Please enter a gender (0 for male and 1 for female " << endl;
cin >> gender;
cout << " Please enter the femur length" << endl;
cin >> femurLength;
if (gender == 0)
{
cout << "The estimated hieght is " << height << endl;
}
else
{
cout << "The estimated hieght is " << heightI << endl;
}
}
int main(int argc, const char * argv[])
{
cout << "Welcome inspector, " << endl;
return 0;
}

在收到输入后,您需要向下移动sum变量,而且可能不需要初始化mW和hW,这实际上是风格和代码练习。至于你关于单位的问题,我不太明白

如果你想传递变量,你需要通过值、指针或引用,或者可怕的全局变量来传递它们。请不要做最后一个!通过值传递变量通常是最简单的方法,本质上只是复制值!这实际上非常简单,只需在函数定义/声明中添加一个参数,然后将变量传递到函数调用中!

最新更新