?
Solved

change from C to F

Posted on 2005-04-15
1
Medium Priority
?
323 Views
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;

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

Accepted Solution

by:
cup earned 200 total points
ID: 13793259
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.  
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

750 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