help with my very first project - war: capitalists and communists

hi!

this code seems to work...but the number of capitalists doesn't go down! help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  
#include <iostream>
#include <string>
#include <random>
#include <ctime>

using namespace std;

int main()
{
   default_random_engine randomGenerator(time(0));
   uniform_int_distribution<int> attackRoll(1, 6);

int numcap;
int numcom;

cout << "///WAR: CAPITALISTS VS. COMMUNISTS///\n" << endl;
cout << "Input the number of CAPITALISTS:\n";
cin >> numcap;
cout << "There will be " << numcap <<" capitalists in the war.\n" << endl;
cout << "Input the number of COMMUNISTS: \n" << endl;
cin >> numcom;
cout << "There will be " << numcom <<" communists in the war.\n" << endl;

cout << "Battle ensues...\n" << endl;

 int attack = attackRoll(randomGenerator);

 while ((numcap > 0) && (numcom > 0)) {

if (attack <= 3) {

  (numcom--);}

else if (attack >= 4) {

   (numcap--);
}
}
cout <<"There are "<< numcom <<" communists and " <<numcap<< " capitalists left on the battlefield.\n" <<endl;


if (numcom == 0) {

 cout << "The capitalists have won!";
}
if (numcap == 0)  {
    cout << "The communists have won!";
}



}


You need to move line 27 inside the while loop. Otherwise it rolls only once.
Topic archived. No new replies allowed.