Thread: help please

  1. #1
    Registered User
    Join Date
    Sep 2003

    help please

    I need help starting this program im required to do for class. I'm going to type up the requirements. All i need is someplace to start and some hints.

    Write a program to produce two charts: one shwoing The Fahrenheit temperatures corresponfing to the Celsisu temperatures from 0 to 200 in increments of 5, and one showing the Celsius tmepratures corresponding to the Fahrenheit temperatures from 0 to 400 in increments of 10. The general formula relating Celsius (C) and Fahrenehit (F) is F=(9/5)C + 32.

    You must write two functions:

    1. int Celsius(int), which converts a Fahrenheit temperature to Celsius
    2. int Fahrenheit(int), which converts a Celsius temperature to Fahrenheit

    Neither function may do any output. You should use these functions in for loops to generate the two charts.
    Each of the two fucntions takes an integer as its argument. So in the body of the function, change the number to a float, do the calculation, and then change it back to an integer. Do not use any coercions. Be sure to take care of any "rounding errors" in the calculations of the temperatures (consider adding .5 to a positive number and subtracting .5 from a negative number).
    All constant values must be declared as consts.
    All output must be to file

    So far ive got For statements i can use but other than that i can not figure out how to start it.
    Here are the For statements
    for(int I=0; i<=200, i+=5) This for statement is for Celsius to fahrenheit.
    For(int j=0; j<=400; i+=10) This one is for Fahrenheit to Celsius.

    Thanks for any help.


  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >So far ive got For statements i can use but other than that i can not figure out how to start it.
    I've found this to be a good starting point for most programs:
    #include <iostream>
    int main()
    My best code is written with the delete key.

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    1. "help please" is not a good title for a thread. Neither is "need help" or "new to programming, neep help." I'd suggest a subject that gives more information about your problem - in this case, getting started on a homework asssignment.
    2. Start off with an empty program. This includes int main(), and not much else. Build this empty program.
    3. Add the prototypes for the functions you are required to have - Celsius and Fahrenheit. The prototype is given to you in the assignment, so just add it to your empty program and build. You should be able to build fine at this point, since you don't call the functions you don't have to define them.
    4. Try to define one of the functions without doing any work, for example, just have it return the same int that was passed in. Build the program.
    5. Try to call this function from main. Pass in an int and save the result into another int. Build the program. If you don't have a debugger that you know how to use, you can add a cout statement to show the int that was returned from the function. Just make sure to remove it later when you turn in your assignment.
    6. Now fill in the function with the correct code based on the algorithm your assignment laid out for you. If you want, don't do the entire algorithm at once, just convert it to a float and then back to an int first, and build the program. The key is to keep building the program after every step and make sure it compiles before moving on.
    7. Once one function compiles and is implemented fully, check the output to make sure that it is converting the degrees correctly. If it is not, figure out what is wrong with your implementation. Once it is, implement the second function in the same way you did the first (make it empty at first, call it in main, implement the actual algorithm one step at a time).
    8. At this point you have two working functions. Now put your for loops in main and call the functions. If you want, you can use cout to test and make sure the results are correct, just make sure to remove it later.
    9. Now worry about how to output the information to the file.
    Remember, compile after every change, and if it gets errors, fix those first. Life will be much easier if you do.

    Good Luck!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Applause for jlou - excellent
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed