fork(3) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. //You can change these numbers here to change the program:
  7. const int MIN_FOOD = 20;
  8. const float POISION_CHANCE = 0.04;
  9.  
  10.  
  11.  
  12. int main(){
  13. float cur_food, food_restoration, end_food, servings_needed;
  14.  
  15.  
  16. cout << "What is the value of your food meter currently?" << endl;
  17. cin >> cur_food;
  18.  
  19. cout << "How much max stamina does food restore?" << endl;
  20. cin >> food_restoration;
  21.  
  22. cout << "What level of food meter would you like to end up with?"<< endl;
  23. cin >> end_food;
  24.  
  25.  
  26.  
  27. servings_needed = (
  28. log(1 - POISION_CHANCE*(cur_food - MIN_FOOD)/food_restoration) -
  29. log(1 - POISION_CHANCE*(end_food - MIN_FOOD)/food_restoration)
  30. ) / POISION_CHANCE;
  31.  
  32.  
  33. cout << "Assuming your food meter can't go below " << MIN_FOOD << " and the food has a "
  34. << POISION_CHANCE*100 << "% chance of food poision, you will have to eat the food an average "
  35. << "of " << servings_needed << " times." << endl;
  36.  
  37. cout << "Without food poisioning, you'd only need to eat " << (end_food - cur_food)/food_restoration <<
  38. " times.\n" ;
  39.  
  40. return 0;
  41. }
  42.  
  43.  
Success #stdin #stdout 0s 4408KB
stdin
60
18
150
stdout
What is the value of your food meter currently?
How much max stamina does food restore?
What level of food meter would you like to end up with?
Assuming your food meter can't go below 20 and the food has a 4% chance of food poision, you will have to eat the food an average of 6.1959 times.
Without food poisioning, you'd only need to eat 5 times.