fork(1) download
  1. #include <iostream>
  2. #include <random>
  3. #include <ctime>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main(){
  10. int hNum, oNum;
  11. cout << endl;
  12. cout << "THIS IS A EPIC LEGENDARY BATTLE BETWEEN HUMANS AND ORCS ^-^" << endl << endl;
  13. cout << "Input the number of humans: "; cin >> hNum;
  14. cout << "Input the number of orcs: "; cin >> oNum;
  15. cout << endl;
  16.  
  17. mt19937_64 randomGenerator(time(NULL));
  18. uniform_int_distribution<int> hATK(0, 40);
  19. uniform_int_distribution<int> oATK(0, 50);
  20.  
  21. int hATKp, oATKp;
  22. int hHP, oHP, HP_lost;
  23. bool combatEnd;
  24. while(hNum != 0 && oNum != 0){
  25. combatEnd = false;
  26. hHP = 155; oHP = 80;
  27. while(combatEnd == false){
  28. hATKp = hATK(randomGenerator);
  29. oATKp = oATK(randomGenerator);
  30. if(hATKp > oATKp){
  31. HP_lost = hATKp - oATKp;
  32. oHP -= HP_lost;
  33. }
  34. if(oATKp > hATKp){
  35. HP_lost = oATKp - hATKp;
  36. hHP -= HP_lost;
  37. }
  38. if(hHP <= 0){
  39. hNum--;
  40. combatEnd = true;
  41. }
  42. if(oHP <= 0){
  43. oNum--;
  44. combatEnd = true;
  45. }
  46. }
  47. }
  48. cout << "Battle begin!" << endl;
  49. if(hNum != 0){
  50. cout << "Humans win!" << endl;
  51. cout << hNum << " humans remained" << endl;
  52. }
  53. if(oNum != 0){
  54. cout << "Orcs win!" << endl;
  55. cout << oNum << " orcs remained" << endl;
  56. }
  57. return 0;
  58. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
THIS IS A EPIC LEGENDARY BATTLE BETWEEN HUMANS AND ORCS ^-^

Input the number of humans: Input the number of orcs: 
Battle begin!