我想寫一個C++程序,它由3個函數組成,一個用於輸入,一個用於計算,另一個用於輸出。該程序應該以英尺和英寸爲輸入,然後將轉換後的米和釐米值打印回用戶。我覺得有什麼問題通過引用調用,因爲我仍然在學習如何正確地使用它,反正這裏的代碼寫3個函數將C和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;
}
使它成爲'void input(double&feet,double&inches)' –
另外,calc不會返回任何東西。 –
您已將'functional-programming'添加到標籤。然而你的程序完全是程序性的。另外,請縮進您的代碼。 – user2079303