change from C to F

Posted on 2005-04-15
Last Modified: 2010-04-01
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;


      //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;

      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;

      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??
Question by:cuong5985
    1 Comment
    LVL 11

    Accepted Solution

    You didn't say what it printed.  

    In your conversion of C to F, change your calculation to (9.0 * C) / 5.0 + 32.0.  It is probably suffering from automatic promotion problems.  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now