2016-11-10 1 views
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; 
} 

도움을 주시면 감사하겠습니다. 감사!

+1

http://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – Biffen

+0

'meters * = variable1'은'meters = 미터 * variable1', 즉 곱셈의 결과를'me ters'. –

답변

1
meters *= variable1; 
centimeters *= variable2; 

해야

variable1 *= meters; 
variable2 *= centimeters; 

마지막 코멘트는 말했다 무엇 : 당신이 참조 (variable1variable2)를 통과 한 변수에 제품을 할당하지 않는, 그래서 그 가치가 없습니다 1과 0의 원래 입력에서 변경.

+0

언제든지 내 친구, 기꺼이 도와주세요. –