Ask Experts Questions for FREE Help !
Ask
    Rebekah_S's Avatar
    Rebekah_S Posts: 3, Reputation: 1
    New Member
     
    #1

    Oct 23, 2007, 05:52 PM
    No error messages, but output keep
    I am very new to the world of C++, but was asked to program a Fahrenheit to Celsius converter application. I FINALLY got the code to not give me any error messages, but every time I execute the application, the output answer for celsius is 0. Could anyone help me determine where the problem is??




    #include <iostream>
    #include <iomanip>

    using std::cout;
    using std::cin;
    using std::endl;
    using std::setprecision;
    using std::ios;
    using std::setiosflags;


    //function prototypes
    int getFahrenheit();
    int calcCelsius(int, int);


    int main()
    {
    int far = 0;
    int subt = 32;
    int cel = 0;

    far = getFahrenheit();





    //display celTemp
    cout << setiosflags(ios::fixed) << setprecision(0);
    cout << "Celsius temperature is: " << cel << endl;

    return 0;
    } //end of main function

    //*****function definitions*****
    int getFahrenheit()
    {
    double FahrenH = 0.0;
    cout << "Enter temperature in Fahrenheit: ";
    cin >> FahrenH;
    return FahrenH;
    } //end of getFahrenheit function

    int calcCelsius(int far, int subt)
    {
    int cel = 0.0;
    cel = (5.0*(far - subt)/9.0);
    return cel;
    } //end of calCelsius function
    Marriedguy's Avatar
    Marriedguy Posts: 474, Reputation: 115
    Full Member
     
    #2

    Oct 23, 2007, 06:18 PM
    I think you are using the wrong data type "int" this for whole numbers. "float" is used for decimal numnbers. Hope this helps.
    Rebekah_S's Avatar
    Rebekah_S Posts: 3, Reputation: 1
    New Member
     
    #3

    Oct 23, 2007, 06:30 PM
    changing to "float" didn't seem to help... my solution keeps being "0" when executed. It seems to be more of a logical-type problem. (i.e. is part of the equation being calculated as 0?)
    asterisk_man's Avatar
    asterisk_man Posts: 476, Reputation: 32
    Full Member
     
    #4

    Oct 24, 2007, 05:53 AM
    You never called the calcCelsius function to set the cel variable in main(). With your current implementation you need to add the following code below where you have far = getFahrenheit():
    cel=calcCelsius(far, 32)

    On a side note, why is subt a parameter of calcCelsius()? Is there any case where this isn't going to be 32?

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Error messages [ 1 Answers ]

I am having 2 different error messages I need help with please. The first one is as follows: An error has occurred in the script on this page line: 7, char: 4, error: permission denied, code: 0, and then a url. Then, Do you want to continue running scripts on this page? And a yes or no box. ...

Error Messages [ 1 Answers ]

Hi, When working on my computer, I a blue screen pops up with an error message. Then starts dumping memory and counting to 100. The computer restarts after the numbers get to 100. These messages have started coming up about once every 2 - 3 hours now. Each time I get one of the following...

DirectSound output v2.2.6 error [ 1 Answers ]

I installed a new Soundblaster soundcard and installed the associated software. This not only corrupted a bunch of my files, it also prevented my old sound card from working. I removed all the software and hardware, restored my computer to an earlier date and reinstalled my old soundcard. All...

HELP - Error messages [ 2 Answers ]

I keep getting the following error message: Runner error Could not load target dll ("Invalid BackWeb application id 4448364", error code 126) I only started getting this after I downloaded Yahoo's antispyware toolbar for my internet explorer. I downloaded spybot search & destroy and scanned...

HELP - Error messages! [ 4 Answers ]

I keep getting the following error message: Runner error Could not load target dll ("Invalid BackWeb application id 4448364", error code 126) I only started getting this after I downloaded Yahoo's antispyware toolbar for my internet explorer. I downloaded spybot search & destroy and scanned...


View more questions Search