waiting for a for loop to make 2 iterations before making a function call.

Is there a way to make a for loop iterate twice then call the function then iterate twice more. I am attempting a simple war style card game using arrays and for loops, right now my code will deal out the cards but the function call for who wins runs after every iteration of the for loop and I need it to run after every 2 iterations so player one and player 2 both have cards before it determines who won the hand. thanks

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <iomanip>				// for setw

using namespace std;
char player1;
char player2;
int p1score = 0;
int p2score = 0;

struct Card 
{
	char f;
	char s;
};

void filldeck(Card [], char [], char []);
void shuffle(Card []);
void deal(Card []);
void whoWon();


int main()
{
	Card deck[52];

	char face[13] =
		{'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
		
	char suit[4] = {'H', 'D', 'C', 'S'};

	filldeck(deck, face, suit);
	
	shuffle( deck );
	deal( deck );
	
	return 0;
}

void filldeck(Card wDeck[], char wFace[], char wSuit[])
{
	for (int i = 0; i < 52; i++)
	{
		wDeck[i].f = wFace[ i % 13 ];
		wDeck[i].s = wSuit[ i / 13 ];
	}
}
void shuffle(Card wDeck [])
{
	srand( time(0) );
	for (int i = 0; i < 52; i++)
	{
		int j = rand() % 52;
		Card temp = wDeck[ i ];
		wDeck[ i ] = wDeck[ j ];
		wDeck[ j ] = temp;
	}
}	

void deal(Card wDeck [] )
{
	
	
	int count = 0; 
	for (int i = 0; i < 52; i++){
		if (count %2 == 0){
			player1 = wDeck[i].f;
			cout << "Player 1's card:" <<setw(5) << wDeck[ i ].f << 
                         " of " << wDeck[i].s << endl;
		}
		else{
			player2 = wDeck[i].f;
			cout << "Player 2's card:" <<setw(5) << wDeck[ i ].f << 
                        " of " << wDeck[i].s << endl;
 		}
		whoWon();
		count++;
	}
	cout << "Player 1's score is: " << p1score << endl;
	cout << "Player 2's score is: " << p2score << endl;
}

void whoWon(){
	if(player1 > player2){
		cout << "player 1 wins" << endl;
		p1score++
	}
	else if(player2 >player1){
		cout << "player 2 wins" << endl;
		p2score++
	}
	else{
		cout << "Its a Draw" << endl;
	}
}
After thinking on it a bit more I realized that I could check if count is even and if it was then
I could call the whoWon() function. If there is a more elegant way to do this I would be open to suggestions.
Topic archived. No new replies allowed.