Problem with inialization: for Class

How do i initalize output1 and output2?

[code]
#include <iostream>
using namespace std;
//Conversion from feet to meters; conversion1 = 0.3048;
//Conversion from meters to centimeters; conversion2 = 100;
//Conversion from foot to inches; conversion3 = 12;
//Conversion from inches to centimeters; conversion4 = 0.39370;
void getInput(int& feet, double& inches);
void Calc(int feet, double inches);
void give_output(int meters, double centimeters, int feet, double inches);
int main()
{
int input1, output1; double input2, output2; char ans;
do
{
getInput(input1, input2);
Calc(input1, input2);
give_output(output1, output2, input1, input2);
cout << "This Program calculates Ft and In to M and Cm.";
cout << "The value of feet, inches" << input1 << ","
<< input2 << endl;
cout << "conversion from feet, inches to meters, centimeters" << output1 << ","
<< output2 << endl;
cout << "So the new measurements are in meters, centimeters" << output1 << ","
<< output2 << endl;
cout << "Do you wish to do another calculation /n";
cout << "press y for yes and n for no /n";
cin >> ans;
}
while(ans == 'y' || ans == 'Y');
return 0;
}
void getInput(int& feet, double& inches)
{
using namespace std;
cout << "Please enter the length in feet ";
cout << "and in inches. ";
cin >> feet
>> inches;
}
void Calc(int feet, double inches)
{
double meters;
double centimeters;
meters = feet * 0.0348;
centimeters = inches / 0.39370;
}
void give_output(int meters, double centimeters, int feet, double inches)
{
using namespace std;
cout << "The new measurements in meters, centimeters "
<< meters << ',' << centimeters << endl;
}
Last edited on
You have more problems that just this. You're not passing the values around properly. Consider breaking your logic out some more so you have these functions.
1
2
double calculateMeters(int feet);
double calculateCenitmeters(double inches);


I would also rename your input and output variables to something more useful like (input_feet, input_inches, output_centimeters, output_meters) etc.

You have used the logic needed to assign values with your getInput() method. So use reference variables or return variables when calculating
Topic archived. No new replies allowed.