Advertisement
Karsol

Untitled

Dec 4th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <random>
  5. using namespace std;
  6.  
  7. int main(void) {
  8.  
  9.     //Get the input from user
  10.     int numHumans;
  11.     int numZombies;
  12.     cout << "**Humans vs. Zombies**\n\n" << "How many Humans are there: ";
  13.     cin >> numHumans;
  14.     cout << "How many Zombies are there:";
  15.     cin >> numZombies;
  16.     cout << "CHARGE!!!!!!!!" << endl;
  17.  
  18.     //random number gen using time as the seed
  19.     mt19937 randomGenerator(time(0));
  20.     //random numbers attached to variable for humans and zombies
  21.     uniform_real_distribution<float>attackHuman(1.00f, 2.00f);
  22.     uniform_real_distribution<float>attackZombie(1.00f, 2.00f);
  23.  
  24.    
  25.     int i = 0;
  26.     int deadZombies = 0;
  27.     int deadHumans = 0;
  28.  
  29.     //makes sure it loops once for each solider in both armys
  30.     for (int i = 0; i < (numHumans + numZombies); i+= 1) {
  31.                
  32.     //checks to make sure there is still soliders in the amry
  33.     while ((deadHumans <= numHumans) && (deadZombies <= numZombies)){
  34.    
  35.     // randomise attack
  36.             float zombieATK = attackZombie(randomGenerator);
  37.             float humanATK = attackHuman(randomGenerator);
  38.     // refresh the health of both soliders
  39.             float humanHP = 2.00f;
  40.             float zombieHP = 2.00f;
  41.  
  42.     // deals the damage
  43.                 humanHP = humanHP - zombieATK;
  44.                 zombieHP = zombieHP - humanATK;
  45.  
  46.     // checks to see who did more
  47.                 if (humanHP > zombieHP) {
  48.                     deadZombies++;
  49.                 }
  50.  
  51.                 else {
  52.                     deadHumans++;
  53.                 }
  54.     // adds one to i which counts for one dead solider  
  55.         i++;
  56.         }
  57.  
  58.     }
  59.    
  60.     cout << "zombies:" << deadZombies << endl;
  61.     cout<< "humans:" << deadHumans << endl;
  62.    
  63.     // less dead = winners
  64.     if (deadZombies < deadHumans) {
  65.         cout << "ZOMBIES WIN!!!" << endl;
  66.     }
  67.  
  68.     else {
  69.         cout << "HUMANS WIN!!!!!" << endl;
  70.     }
  71.    
  72.     system("PAUSE");
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement