Thread: HELP | Write a program that estimates the temperature in a freezer (in C)

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    7

    Exclamation HELP | Write a program that estimates the temperature in a freezer (in C)

    Write a program that estimates the temperature in a freezer (in C) given the elapsed time (hours) since a power failure. Assume this temperature ( T ) is given by

    -2015-04-28_2315-png

    where t is the time since the power failure. Your program should prompt the user to enter how long it has been since the start of the power failure in whole hours and minutes. Note that you will need to convert the elapsed time into hours. For example, if the user entered 2 30 (2 hours 30 minutes), you would need to convert this to 2.5 hours.

    Please write full C Programming Code. Thanks in Advance
    Last edited by AliAsadUrRehman; 04-28-2015 at 12:22 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,401
    What have you tried and what help do you need?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    Quote Originally Posted by laserlight View Post
    What have you tried and what help do you need?
    Hi, I need C Code to submit my assignment. If you can please

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,401
    Quote Originally Posted by AliAsadUrRehman
    Hi, I need C Code to submit my assignment. If you can please
    I probably can help you, but as you say, it is your assignment, not mine, hence I am willing to help you, but not to do your assignment for you. On a related note, refer to the homework policy.

    So, start by understanding your assignment's requirements. Plan how you would go about implementing your program. Then, write a small part of your program, compile and test it. Then write another part, compile and test, etc. We actually have a thread with a suggested development process to help you.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    Quote Originally Posted by laserlight View Post
    I probably can help you, but as you say, it is your assignment, not mine, hence I am willing to help you, but not to do your assignment for you. On a related note, refer to the homework policy.

    So, start by understanding your assignment's requirements. Plan how you would go about implementing your program. Then, write a small part of your program, compile and test it. Then write another part, compile and test, etc. We actually have a thread with a suggested development process to help you.

    Here is my code. Is it correct or something is wrong.

    Code:
    #include <stdio.h>
    
    #define HOUR 60
    
     
    int main() 
    {
     
        int hour=0; //hour input
        int minutes=0; //minute input
    
        double temp=0; //temperature output
    
     
     
     
        printf("Power Failure Freezer Temperature Estimate. \n");
    
        printf("How long (in hours and minutes) since the power failure to the freezer?>");
    
         
        scanf("%d" "%d", &hour &minutes);
    
     
        time = hour + minutes; //convert hours to minutes
     
         
        temp = ((4*(time*time)/(time+2))-20); //Calculate the temperature 
        printf("The estimated temperature inside your freezer is %3.1f degrees Celsius.", temp); //displays results
    
     
     
        return 0;
    
     
    
    }

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,401
    This is wrong:
    Code:
    time = hour + minutes; //convert hours to minutes
    For starters, you did not declare variable named time. I suggest not declaring a variable named time because time is also the name of a function from the standard library. You could use say, elapsed_time.

    Next, even if you did declare elapsed_time to be a double, you cannot just add hour and minutes. Rather, you are supposed to convert minutes into hours and add that to hour (so your comment is wrong too).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    4,465
    Note that you will need to convert the elapsed time into hours.
    Did you remember to convert the minutes into hours?

    What type of variable is time? Remember an int can have no fractional parts.

    Jim

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,793
    "%d" "%d"
    more common would be to write as
    "%d%d"

    time = hour + minutes; - if you add 2 hour and 4 minutes together you get 6 but is the meaning of this number is beyond my.

    time is a function name - you need a variable to hold time in hours, and it should be double since 30 min is 0.5 hours for example


    temp is mostly used for temporal variable with no meaning as to store some intermediate result. So for the temperature I would use some other not so confusing name
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Temperature conversion program bug.
    By prafiate in forum C Programming
    Replies: 6
    Last Post: 08-13-2012, 09:40 AM
  2. Temperature Conversion Program
    By llind212 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2011, 11:37 PM
  3. Need help with temperature conversion program
    By Aequitas in forum C Programming
    Replies: 4
    Last Post: 03-06-2011, 08:28 PM
  4. Asympotic Estimates of Run-Times
    By jturner38 in forum C++ Programming
    Replies: 5
    Last Post: 12-01-2010, 01:27 AM
  5. Freezer
    By siavoshkc in forum C++ Programming
    Replies: 7
    Last Post: 01-21-2006, 02:24 AM

Tags for this Thread