2016-11-10 6 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

いつでも私の友人、助けてうれしい –