0
我應該做一個代碼,從腳和英寸轉換爲米和釐米。但是當我運行我的代碼時,我沒有得到我應該得到的。例如,我輸入1英尺和0釐米。我應該得到0.3048米和0釐米,但我得到1米和0釐米。幫幫我!C++輸出轉換錯誤
#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;
}
任何幫助表示讚賞。謝謝!
http://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – Biffen
'米* =變量1'相當於'米=米*變量1「,即你把乘積的結果賦給'我ters'。 –