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
'meters * = variable1'은'meters = 미터 * variable1', 즉 곱셈의 결과를'me ters'. –