• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need help with a math equation

mattg1981

Senior member
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.
 
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;
 
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.
 
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. 🙂
 
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.
 
Back
Top