Void conversion function for feet and inches to meters and centimeters?

This is a discussion on Void conversion function for feet and inches to meters and centimeters? within the C++ Programming forums, part of the General Programming Boards category; I got all the rest of the code working but I just can't figure out how to convert the input ...

  1. #1
    Registered User CplusplusNewb's Avatar
    Join Date
    Oct 2009
    Location
    Chicago
    Posts
    17

    Void conversion function for feet and inches to meters and centimeters?

    I got all the rest of the code working but I just can't figure out how to convert the input into meters and centimeters. For example I know that 1 foot is 0.3048 meters, so I need to multiply the feet by 0.3048.

    But every time I run it, it never converts it, it just says 6.78222e-308 meters.

    Here's the code:

    Code:
    #include <iostream>
    using namespace std;
    
    void userInput(double& feet, double& inches);
    void convertUStoMetric(double& meters, double& centimeters);
    void output(double meters, double centimeters);
    
    int main()
    {
    	double unit, subunit;
    	char redo = 'y';
    	
    	while (redo == 'y' || redo == 'Y')
    	{
    	
    			userInput(unit, subunit);
    			convertUStoMetric(unit, subunit);
    			output(unit, subunit);
    		
    		cout << "Would you like to run it again? Y/N: ";
         	cin >> redo;
         	cout << "\n";
    	}
    	
    	system("pause");
        return 0;   
    }
    
    void userInput(double& feet, double& inches)
    {
    	cout << "Enter the feet and inches with a space in between each: ";
    	cin >> feet;
    	cin >> inches;
    	cout << "\n";	
    }
    
    void convertUStoMetric(double& meters, double& centimeters)
    {
    	double total;
    	total = total * 0.3048;
    	meters = total;
    	
    	
    }
    
    void output(double meters, double centimeters)
    {
    	cout << "The converted measurements are " << meters << " meters and " << centimeters << " centimeters.";
    	cout << "\n\n";	
    }
    I don't understand how I'm supposed to do the convertUStoMetric conversion function.

    Am I supposed to create a new variable?

  2. #2
    Registered User CplusplusNewb's Avatar
    Join Date
    Oct 2009
    Location
    Chicago
    Posts
    17
    OK never mind about the conversion, I got

    Code:
    meters = meters * 0.3048;
    and it worked for the feet to meters conversion.

    But I have to make it so there are no decimals in it. If it's 10 feet to meters, it'll have to be 3 meters and ? centimeters.

  3. #3
    Registered User CplusplusNewb's Avatar
    Join Date
    Oct 2009
    Location
    Chicago
    Posts
    17
    Wow thanks that actually works great and does exactly what I want it to!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21