cant seem to get this war program to repeat if a tie. Need to give each player one more card if tie.

I created this war game and I need it to repeat if a tie. Any help appreciated.

int main()
{
srand(time(0));
rand();

// Variables
int computerRank = rand() % 14 +2;
int computerSuit = rand() % 3 +0;
int humanSuit = rand() % 3 +0;
int humanRank = rand() % 14 +2;

// its a tie loop
do
{
cout << " It's a tie!";
cin >> computerRank;
cin.ignore(1000, 10);
} while (computerRank != humanRank);


// Computers rank and suit
cout << "computers card is a " ;

switch(computerRank)

{
case 2:

cout << "2";

break;
case 3:
cout << "3";

break;
case 4:

cout << "4";

break;
case 5:

cout << "5";

break;
case 6:
cout << "6";

break;
case 7:

cout << "7";

break;
case 8:
cout << "8";

break;
case 9:

cout << "9";

break;
case 10:

cout << "10";

break;
case 11:

cout << "jack";

break;
case 12:
cout << "queen";

break;
case 13:

cout << "king";

break;
case 14:
cout << "Ace";

break;
}

switch(computerSuit)
{

case 0:

cout << " of Spades" << endl;
break;

case 1:
cout << " of Diamonds" << endl;

break;
case 2:

cout << " of hearts" << endl;

break;
case 3:

cout << " of clubs" << endl;
break;
}

//humans rank and suit
cout << "humans card is a " ;

switch (humanRank)

{
case 2:

cout << "2";

break;
case 3:
cout << "3";

break;
case 4:

cout << "4";

break;
case 5:

cout << "5";

break;
case 6:
cout << "6";

break;
case 7:

cout << "7";

break;
case 8:
cout << "8";

break;
case 9:

cout << "9";

break;
case 10:

cout << "10";

break;
case 11:

cout << "jack";

break;
case 12:
cout << "queen";

break;
case 13:

cout << "king";

break;
case 14:
cout << "Ace";

break;
}

switch(humanSuit)

{

case 0:

cout << " of Spades" << endl;
break;

case 1:
cout << " of Diamonds" << endl;

break;
case 2:

cout << " of hearts" << endl;

break;
case 3:

cout << " of clubs" << endl;
break;
}


if (computerRank > humanRank)
cout << "Computer wins!";
if (humanRank > computerRank)
cout << "human wins!";




}//main
Last edited on
The only loop in your program is here...
(which btw is missing a ; after the while statement)
1
2
3
4
do 
{ 
cout << " It's a tie!";
} while (computerRank == humanRank)


That would cause an infinite loop if computerRank is equal to humanRank. You need to move the do statement at the beginning of your code after your variables are declared, but before they are initialized.

Psuedo code:
1
2
3
4
5
6
7
8
9
10
11
12

//declare variables
do{
  //Initialize variables to randoms
  //Convert and display texts
  //Compare variables
      //Display results
      //If NOT a tie, break do loop
}
//Not a tie if we are here - end program

Last edited on
I have gone and corrected this and it appears to only display the text its a tie. ughh frustrating. Any help would be appreciated.
Topic archived. No new replies allowed.