Link to home
Start Free TrialLog in
Avatar of cuong5985
cuong5985

asked on

change from C to F

Ask the user what conversion he/she wants to do: F to C, C to F, Cm to Feet, Feet to Cm. Use an error handling function.

Test your program with the following data:

C = 0;
F = 0
Feet = 6;
Cm = 100;

This is my program:
#include <iostream.h>
#include <stdlib.h>
#define DEBUG false

float Celsius (float F);
float Fahrenheit (float C);
float Feet (float cm);
float Centimeters (float ft);

int main()
{
      float F, C, ft, cm;

      cout.setf(ios::fixed);
      cout.setf(ios::showpoint);
      cout.precision(2);

      //Get input from the users
      cout <<"Enter the degree of Celsius: ";
      cin >> C;
      cout <<"Enter the degree of Fahrenheit: ";
      cin >> F;
      cout <<"Enter number of Feet: ";
      cin >> ft;
      cout <<"Enter number of Centimeters: ";
      cin >> cm;

      //Output
      cout <<"Degree of Celsius is: "<<Celsius(F)<<endl;
      cout <<"Degree of Fahrenheit is: "<<Fahrenheit(C)<<endl;
      cout <<"Number of feet is: "<<Feet(cm)<<endl;
      cout <<"Number of centimeters is: "<<Centimeters(ft)<<endl;

      system("PAUSE");
      return 0;
}

float Celsius (float F)
/*********************************************************************
Function Name: Celsius
Purpose: Convert number of degree of Fahrenheit to the degree of Celsius.
Arguments: F
Returns: celsius
*********************************************************************/
{
    if (DEBUG)
    {
       cout <<"Degree of Celsius is: "<<Celsius;
       cout <<endl;
    }
    return ((F - 32)/1.8);
}

float Fahrenheit (float C)
/*********************************************************************
Function Name: Fahrenheit
Purpose: Convert number of degree of Celsius to the degree of Fahrenheit.
Arguments: C
Returns: fahrenheit
*********************************************************************/
{
    if (DEBUG)
    {
       cout <<"Degree of Fahrenheit is: "<<Fahrenheit;
       cout <<endl;
    }
    return (9.0/5 * C + 32);;
}

float Feet (float cm)
/*********************************************************************
Function Name: feet
Purpose: Convert number of cm to the number of feet.
Arguments: cm
Returns: feet
*********************************************************************/
{
    if (DEBUG)
    {
       cout <<"Number of feet is: "<<Feet(cm);
       cout <<endl;
    }
    return (cm/30.48);
}

float Centimeters (float ft)
/*********************************************************************
Function Name: feet
Purpose: Convert number of feet to centimeters
Arguments: ft
Returns: cm
*********************************************************************/
{
    if (DEBUG)
    {
       cout <<"Number of centimeters is: "<<Centimeters (ft);
       cout <<endl;
    }
    return (ft*30.48);
}

I just wornder what wrong with my program??
ASKER CERTIFIED SOLUTION
Avatar of cup
cup

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial