Check Values within a range

This is a discussion on Check Values within a range within the C++ Programming forums, part of the General Programming Boards category; I am running a program that calculates heat dissipation of heat copper sphere and I need to run the calculations ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    8

    Check Values within a range

    I am running a program that calculates heat dissipation of heat copper sphere and I need to run the calculations until the temperature of the sphere is within .1, that is either +.1 or -.1 of a set safe temperature. I have no problems getting my program to loop to find the correct temperature values. I just can't seem to find the correct test to get the loop to stop. If you have any suggestions please let me know. I uploaded the file
    Attached Files Attached Files

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Without reading the code, "distance from" is generally given by "fabs". So fabs(temperature-5) or whatever is what you would want to check.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    8
    I want to test for both the upper and lower limit. So taking the absolute value will not work. I need to see if my calculated value is within the range. Like this 24.9<calc_temp<25.1

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    There needs to be two if statements to check this:
    Code:
    if (this && that) { printf("in range\n"); }
    What can you say about calc_temp and your range that will satisfy this and that?

    Think.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    8
    My if test currently reads
    if(temp>=safe_temp-.0999 && temp<=safe_temp+.0999)
    test=1;
    else
    test=0;

    I have a while loop that will stop if test==1, but it doesn't stop when I want it to.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by ianrice View Post
    I want to test for both the upper and lower limit. So taking the absolute value will not work. I need to see if my calculated value is within the range. Like this 24.9<calc_temp<25.1
    Which is exactly what I said. fabs(calc_temp-25) < 0.1 (i.e., "the distance from calc_temp to 25 needs to be less than 0.1").

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-06-2010, 12:42 AM
  2. Range of Values
    By devilsknight in forum C Programming
    Replies: 1
    Last Post: 06-03-2006, 04:16 PM
  3. Please help to check.
    By nicoleha in forum C Programming
    Replies: 16
    Last Post: 12-07-2005, 03:29 PM
  4. Random numbers
    By nicoleha in forum C Programming
    Replies: 20
    Last Post: 12-06-2005, 04:00 PM
  5. Replies: 1
    Last Post: 02-03-2005, 03:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21