fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. struct Monster
  6. {
  7. string name;
  8. int combatPower;
  9. };
  10.  
  11. bool captureAttempt(Monster monster)
  12. {
  13. int chance = 0;
  14. if(monster.combatPower < 100)
  15. chance = rand()%1;
  16. else if(monster.combatPower > 99)
  17. chance = rand()%3;
  18. else if(monster.combatPower > 200)
  19. chance = rand()%7;
  20.  
  21. if(chance == 0)
  22. return true;
  23. else return false;
  24. }
  25.  
  26. string randomNameGenerator()
  27. {
  28.  
  29. string names[25] = {"Charmander", "Bulbasor", "Squrtile", "Pidgey", "Pikachu",
  30. "Sandshrew", "Zubat", "Mankey", "Abra", "Magikarp",
  31. "Eevee", "Rattata", "Vulpix", "Scyther", "Jigglypuff",
  32. "Geodude", "Onix", "Staryu", "Snorlax", "Mewtwo",
  33. "Oddish", "Caterpie", "Spearow", "Charizard", "Zapdos",};
  34. return names[rand()%24];
  35. }
  36.  
  37. Monster setMonster(Monster monster)
  38. {
  39. monster.name = randomNameGenerator();
  40. monster.combatPower = rand()%450 + 1;
  41. return monster;
  42. }
  43. int main() {
  44. srand(time(NULL));
  45. Monster monster;
  46. char input;
  47. bool didCatch = false;
  48. int pokeballs = 5;
  49.  
  50. while(true)
  51. {
  52. pokeballs--;
  53. monster = setMonster(monster);
  54. didCatch = captureAttempt(monster);
  55. if(didCatch)
  56. {
  57. cout<<"Gotcha! You caught the monster "<<monster.name<<"!"<<endl;
  58. cout<<"Attempt to catch again? (Y?N): " ;
  59. }
  60. else
  61. cout<<"broke free! Attempt to catch again? (Y/N)"<<endl;
  62. cin>>input;
  63. if(input == 'N' || input == 'n')
  64. {
  65. cout<<"\nGot away safely."<<endl;
  66. exit(0);
  67. }
  68. if(pokeballs == 0)
  69. {
  70. cout<<"\nYou do not have any pokeballs, so you ran and got away safely.";
  71. exit(0);
  72. }
  73. else
  74. {
  75. cout<<"\nRemianing pokeballs: "<<pokeballs<<endl;
  76. }
  77. }
  78. return 0;
  79. }
Success #stdin #stdout 0s 16072KB
stdin
Y Y Y N
stdout
Gotcha! You caught the monster Spearow!
Attempt to catch again? (Y?N): 
Remianing pokeballs: 4
broke free! Attempt to catch again? (Y/N)

Remianing pokeballs: 3
broke free! Attempt to catch again? (Y/N)

Remianing pokeballs: 2
broke free! Attempt to catch again? (Y/N)

Got away safely.