Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

trying to debug a second program can you help

posthimposthim Member Posts: 15
displays a Celsius temperature

#include
using namespace std;

//function prototypes
int getFahrenheit();
float calcCelsius(int);
int displayCelsius();

int main()
{
//declare variables
int fahrenheit = 0;
float celsius = 0.0;

//get input item
fahrenheit = getFahrenheit();

//calculate Celsius
celsius = calcCelsius(fahrenheit);

//display output item
cout << fixed;
cout << "Celsius: " << celsius << endl;
return 0;
} //end of main function

//*****program-defined functions*****

int getFahrenheit()
{
int tempF = 0;
cout << "Enter Fahrenheit temperature: ";
cin >> tempF;
return tempF;
} //end of getFahrenheit function

float calcCelsius(int tempFahrenheit)
{
float tempC = 0.0;
tempC = 5.0 / 9.0 * (tempFahrenheit - 32);
return tempC;
} //end of calcCelsius function

displayCelsius()
{
int temp;
cout << "Dipl temp: ";//display the temperture calculated from fehrenheit to celsius
return temp;//return celsius temperature
} //end of dsiplayCelsius function


Comments

  • Geeth AsokanGeeth Asokan Member Posts: 127
    Hi,

    I have modified your code to read and it works!:

    [code]
    #include
    #include

    // Function prototypes
    float calcCelsius(float);

    void main(void)
    {
    // Declare the variables
    // Temperature in Fahrenheit
    float tempF;

    // User enters temperature in fahrenheit
    cout << "Enter fahrenheit temperature: ";
    cin >> tempF;

    // This converts Fahrenheit temperature into Celsius
    // temperature

    calcCelsius(tempF);

    // Display the celsius temperature
    cout << tempF << " in fahrenheit is " << calcCelsius(tempF)
    << " in celsius
    ";

    system("PAUSE");
    }

    //*****Program-defined functions*****

    // Conversion program from fahrenheit into celsius
    float calcCelsius(float tempF)
    {
    // Temperature in Celsius
    float Celsius;
    Celsius = 5.0/9.0*(tempF-32);
    }
    [/code]

    You could have two more program-defined functions but I'l let you do this.

    Hope this helps,

  • magnus702magnus702 Member Posts: 3
    I have this code 4U which solves same kind of problem.
    I hope U can use it!



    #include
    #include

    //funct. declerations:

    void initialize_screen();
    //separets current output from the
    //output from previously run program

    double celsius(double fahrenheit);
    //converts Faahrenheit to Celsius

    void show_results(double f_degrees, double c_degrees);
    //displays output

    int main()
    {
    using namespace std;
    double f_temperature, c_temperature;

    initialize_screen();
    cout << "I will convert a Fahrenheit temperature"
    << " to Celsius.
    "
    << "Enter a temperature in Fahrenheit: ";
    cin >> f_temperature;

    c_temperature = celsius(f_temperature);

    show_results(f_temperature, c_temperature);
    getch ();
    }
    //funct. definitions:

    void initialize_screen()
    {
    using namespace std;
    cout << endl;
    }

    double celsius(double fahrenheit)
    {
    return ((5.0/9.0)*(fahrenheit - 32));
    }

    void show_results(double f_degrees, double c_degrees)
    {
    using namespace std;
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);
    cout << f_degrees
    << " degrees Fahrenheit is equivalent to
    "
    << c_degrees << " degrees Celsius.
    ";
    }


  • Justin BibJustin Bib USAMember Posts: 0

    _____ || http://forcoder.org || free video tutorials and ebooks about | PHP, PL/SQL, Python, Scratch, Ruby, R, MATLAB, Assembly, Visual Basic .NET, Visual Basic, Objective-C, Perl, Delphi, Java, Go, C++, JavaScript, Swift, C#, C Dart, Alice, FoxPro, Julia, Transact-SQL, Kotlin, Fortran, Rust, Lisp, VBScript, Apex, Scala, ML, Logo, Ada, Scheme, Crystal, COBOL, D, Clojure, ABAP, F#, Hack, LabVIEW, Prolog, Lua, Bash, Erlang, SAS, Awk |

Sign In or Register to comment.