Need help with a math equation

mattg1981

Senior member
Jun 19, 2003
957
0
76
I have a random double 0 <= rand <= 1. Given two ints X and Y, I need to know rand% between the two. I may not be explaining this well, so here is an example.

num_low = 5;
num_high = 15;
double temp = .77321;

so with those given inputs, I need to find the number that is 77% of the way between 5 and 15.

Btw .. not homework or anything, just have no idea what the math equation is for this.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
double range = num_high - num_low;
double percent = temp * range;
double value = percent + num_low;

Did you fail 8th grade algebra?


Edit: if you want it in one line:
double value = (temp * (num_high - num_low)) + num_low;
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: mattg1981
Originally posted by: notfred
Did you fail 8th grade algebra?

I appreciate the courtesy, thanks for answering my question.

Well, it was a really basic equation. When people post really easy questions, it makes me think that they didn't even try to answer them on thier own. I don't mind helping people when they're stuck, but if they're not even trying, it gets annoying.
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
What annoys me is when people brag about how much smarter they are than everybody else. To each his own I guess... It just seems like the amount of these questions are so rare that you don't need to have an attitude about it. Consider saying it in a more cordial way. :)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: xtknight
What annoys me is when people brag about how much smarter they are than everybody else. To each his own I guess... It just seems like the amount of these questions are so rare that you don't need to have an attitude about it. Consider saying it in a more cordial way. :)

They're not really that rare, usually they're homework questions that people don't feel like doing on thier own. I probably could be more cordial, but I don't know if that has the same effect on making people try a little harder to get the answer themselves before they come and post it here. Of course, I don't know that being kind of rude really has that effect either.

You can usually tell when someone's given some thought to a problem because they tend to include the work they've done so far in thier posts. If they post without including any code or any thoughts on the matter, it's uaually a pretty dead giveaway that they haven't even tried.