我正在尝试编写一个由 3 个函数组成的 C++ 程序,一个用于输入,一个用于计算,一个用于输出。该程序应该将英尺和英寸作为输入,然后将米和厘米的转换值打印回用户。我认为通过引用调用有问题,因为我仍在学习如何正确使用它,无论如何这里是代码
#include<iostream>
using namespace std;
void input(double feet , double inches);
void calc(double &feet , double &inches);
void output(double &feet , double &inches);
void main()
{
double feet1 , inches1;
char ans;
do
{
input(feet1,inches1);
calc(feet1,inches1);
output(feet1,inches1);
cout<<"Would you like to calculate again? y/n : ";
cin>>ans;
}
while(ans == 'y' || ans == 'Y');
}
void input(double feet , double inches)
{
cout<<"Enter feet : ";
cin>>feet;
cout<<"Enter inches : ";
cin>>inches;
}
void calc(double &feet , double &inches)
{
double meters , centimeters;
meters = feet * 0.3048;
centimeters = inches * 2.54;
}
void output(double &feet , double &inches)
{
calc(feet,inches);
cout<<"Converted feet to metres : "<<metres;
cout<<"Converted inches to centimeters : "<<centimeters;
}