I need a C++ function that returns true or false depending on a probability func
ID: 3709437 • Letter: I
Question
I need a C++ function that returns true or false depending on a probability function. This is a function to calculate the probability of a raider attack in Oregon Trail, based on the amount of miles travelled thus far.
Code:
bool Game::raiderChance()
{
double probability = ((((pow(((miles_gone/100) - 4), 2)) + 72) / ((pow(((miles_gone/100) - 4), 2)) + 12)) - 1) / 10;
if (current_milestone == 0)
{
return false;
}
return // true or false (was I attacked by raiders?)
}
Edit: For some reason people are confued on the threshold value? This is a formula out of 10 (if you just read it?) with a decimal value in the numerator. After the formula is calulated, it will be some percentage chance.
Explanation / Answer
raiderChance(current_milestone,miles_gone){
double probability = ((((pow(((miles_gone/100) - 4), 2)) + 72) / ((pow(((miles_gone/100) - 4), 2)) + 12)) - 1) / 10;
if (current_milestone == 0){
return false;
}
boolean flag = (probability >= 0.5) ? true : false ;
return flag;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.