Thread: C++ Help

  1. #1
    nazma
    Guest

    C++ Help

    I have to do the following:
    1. Create a program that will convert from Celsius to Fahrenheit. The user will input a value in Celsius (Integer) and the program will display the temperature converted to Fahrenheit (Integer).

    MY answer is:
    #include <iostream.h>
    #include <stdlib.h>

    void main()
    {
    float Fahrenheit;
    float Celsius;

    cout<< "Temperature Converter\n"
    << "_____________________\n\n";

    cout<< "Fahrenheit \t Celsius.\n";

    for(Fahrenheit = -50; Fahrenheit <= 250; Fahrenheit+=10) {
    Celsius = 5* (Fahrenheit - 32)/9;
    cout<< Fahrenheit << "F\t-\t" << Celsius << 'C' << endl;
    system("PAUSE");
    }

    cout<< "Celsius \t Fahrenheit.\n";

    for(Celsius = -50; Celsius <= 150; Celsius+=5) {
    Fahrenheit = ((float)9/5) * Celsius + 32;
    cout<< Celsius << "C\t-\t" << Fahrenheit << 'F' << endl;
    system("PAUSE");
    }

    cout<< endl << "End of Temperature conversions.\n";

    // Pause program before exiting (for non VisualC++ compiler only).
    system("PAUSE");

    } // end main.


    I HAVE TO DO THE FOLLOWING WITH THE ABOVE:

    1. Modify the program from above to allow the user to continue entering Celsius temperatures until the user enters a sentinel value (you can determine what that sentinel value will be).
    2. Create a function to retrieve the values from the user until the sentinel value is entered. The function will return the average of the values entered as an integer.
    3. From the main function, call the function you created to retrieve the values and return the average. Then convert that average to Fahrenheit and display the results.

    I AM HAVING SOME DIFFICULTY IN MODIFYING THE PROGRAM, I WOULD LIKE TO KNOW IF ANYONE WOULD LIKE TO ASSIST ME IF YOU COULD.
    I REALLY APPRECIATE ALL OF YOUR HELP.I AM REALLY NEW TO C++, NOW LEARNING ON MY OWN.

    Thanks

    Nazma

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    60

    RE Celsius Fahrein Convert

    Hi, I think the idea of the exercise is to give you trouble. The thing with programming is not knowing all the syntax, but learning how to solve problems. The best way I can think of for improving your problem solving skills is to tackle problems!

    One thing I do when a problem seems hard to fathom is to write out the flow of the program in plain English/whatever language...
    Doing this will help you to think through the problem.
    "It compiled, let's ship it!"

    Guitar Australia
    my site for some easy tutorials.

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    What is it exactly that you cannot do?

    Maybe you should read some tutorials about loops( sentinel controlled loops and counter controlled loops ), there are some tutorials on this website, and tons of tutorials on other websites.

    You should also learn to use int main(), and <iostream> without a .h, the FAQ's section in this website will give you a alot information that you need.

    And you should also use code tags.
    none...

  4. #4
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282
    >>1. Modify the program from above to allow the user to continue entering Celsius temperatures until the user enters a sentinel value (you can determine what that sentinel value will be).

    In other words, use a while loop or a do while loop, although
    do while seems perfect for this one... keep looping
    while (variable != -1) (where "-1" is the sentinel.. you can
    change it to whatever value) ... and keep storing those
    values in an array ..


    >>2. Create a function to retrieve the values from the user until the sentinel value is entered. The function will return the average of the values entered as an integer.

    Keep running a loop until your -1 (or any other value that
    you intend to use as a sentinel) is reached and
    read the value one by one from the array and keep
    adding them to a variable (say, "total") and also
    keep counting how many times your loop ran ("count")

    total/count gives you the avg.. just return that value

    >>3. From the main function, call the function you created to retrieve the values and return the average. Then convert that average to Fahrenheit and display the results.
    This question is self explanatory.



    Show some code which tries to answer
    those questions you posted.... if you're still stuck, someone
    will definitely help.

    Good luck

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You want C++ Help in the C++ forum?! Gasp, I'm shocked!!


    As some others have said, you need to do some reading on your own and try to tackle the problem yourself first.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    25
    Maybe this can be for some help?.
    Code:
    #include <iostream>
    
         float Convert(float);
    
     int main()
         {
            float TempFer;
            float TempCel;
    
            std::cout << "Please enter the temperature in Fahrenheit: ";
           std::cin >> TempFer;
           TempCel = Convert(TempFer);
           std::cout << "\nHere's the temperature in Celsius: ";
           std::cout << TempCel << endl;
                   return 0;
        }
    
        float Convert(float TempFer)
        {
           float TempCel;
           TempCel = ((TempFer - 32) * 5) / 9;
           return TempCel;
       }

Popular pages Recent additions subscribe to a feed