# Assignment: HW3
# File: ConvertUnits.py
# Student: Bill Young 
# UT EID: youngwd
# Course Name: CS303E
# 
# Date: September 19, 2024
# Description of Program:  Accept amounts of feet and inches and convert
#    into various English and Metric units. 

# This is a modification for the discussion in class. It differs from the original 
# problem as follows: 
# 1. print numbers to 4 decimal places of precision;
# 2. check that feet and inches entered are non-negative;
# 3. in a second version, line up the decimal points.

###########################################################################
#                                                                         #
#                             Convert Units                               #
#                                                                         #
###########################################################################

"""This program accepts from the user a pair of numbers representing
feet and inches and treats this as one distance measurement.  Assume
that the values entered are floats, but check that they are
non-negative.  The program then prints a report converting this
measurement to several English and metric units.

Enter number of feet: 10
Enter number of inches: 7

10.0 feet and 7.0 inches equals:

English Units
  feet: 10.5833
  inches: 127.0000
  yards: 3.5278
  miles: 0.0020 

Metric Units
  meters: 3.2258
  centimeters: 322.5800
  millimeters: 3225.8000
  kilometers: 0.0032
"""

def main(): 
    """This is the main function from Convert Units."""

    # Accept from the user number of feet.
    inputFeet = float( input("Enter number of feet: ") )

    # Adding code to check that the feet entered is non-negative:
    if inputFeet < 0:
        print("Feet should be a non-negative number.")
        return

    # Accept from the user number of inches.
    inputInches = float( input("Enter number of inches: ") )

    # Adding code to check that the feet entered is non-negative:
    if inputInches < 0:
        print("Inches should be a non-negative number.")
        return

    # At this point we have two variables containing a number of feet and
    # inches.  We now convert them into other measurements. 
    
    # Generate the four English measurements:
    inches = inputFeet * 12 + inputInches
    feet   = inches / 12
    yards  = feet / 3
    miles  = feet / 5280
    
    # Generate the four Metric measurements:
    meters = feet * 0.3048
    centimeters = meters * 100
    millimeters = centimeters * 10
    kilometers  = meters / 1000
    
    # Print the report.  Adding to this version that we'll only keep 
    # four decimal places of accuracy. 

    print()
    print(inputFeet, "feet and", inputInches, "inches equals:\n")
    print("English Units")
    print("  feet:", format(feet, ".4f"))
    print("  inches:", format(inches, ".4f"))
    print("  yards:", format(yards, ".4f"))
    print("  miles:", format(miles, ".4f"), "\n")
    print("Metric Units")
    print("  meters:", format(meters, ".4f"))
    print("  centimeters:", format(centimeters, ".4f"))
    print("  millimeters:", format(millimeters, ".4f"))
    print("  kilometers:", format(kilometers, ".4f"))
    print()

main()


# This is a different version, where the numbers in the display are
# lined up on the decimal points.

def main2():
    inputFeet   = float( input("Enter number of feet: ") )

    # Adding code to check that the feet entered is non-negative:
    if inputFeet < 0:
        print("Feet should be a non-negative number.")
        return

    inputInches = float( input("Enter number of inches: ") )

    # Adding code to check that the feet entered is non-negative:
    if inputInches < 0:
        print("Inches should be a non-negative number.")
        return

    # At this point we have two variables containing a number of feet and
    # inches.  We now convert them into other measurements. 
    
    # Generate the four English measurements:
    inches = inputFeet * 12 + inputInches
    feet   = inches / 12
    yards  = feet / 3
    miles  = feet / 5280
    
    # Generate the four Metric measurements:
    meters = feet * 0.3048
    centimeters = meters * 100
    millimeters = centimeters * 10
    kilometers  = meters / 1000
    
    # Print the report.  Adding to this version that we'll only keep 
    # four decimal places of accuracy, and line up the numbers on the
    # decimal point.

    myFormat = "15.4f"

    print()
    print(inputFeet, "feet and", inputInches, "inches equals:\n")
    print("English Units")
    print("  feet:       ", format(feet, myFormat))
    print("  inches:     ", format(inches, myFormat))
    print("  yards:      ", format(yards, myFormat))
    print("  miles:      ", format(miles, myFormat), "\n")
    print("Metric Units")
    print("  meters:     ", format(meters, myFormat))
    print("  centimeters:", format(centimeters, myFormat))
    print("  millimeters:", format(millimeters, myFormat))
    print("  kilometers: ", format(kilometers, myFormat))
    print()

#main2()
