Working with recursive functions

I am writing a program that will help us understand how recursive functions work by creating a simple dice game. But for some reason the output is wrong and I don't know why.

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
  #include <iostream>
//function prototype:
int payoff(int x, int y, int z);

void loopR1(int R1, int upto);
void loopR2(int R2, int upto);
void loopR3(int R3, int upto);

//global variables:
int total;

using namespace std;
int main(void) {
	cout << "R1\t R2\t R3\t\n" << endl;

	////////////////////
	//first loop
	////////////////////
	loopR1(1, 4);
	printf("\n");

	system("PAUSE");
	return 0;
}
void loopR1(int R1, int upto)
{
	while (R1 < upto){
		loopR2(R1, upto);
		R1++;
	}
}
void loopR2(int R2, int upto)
{
	while (R2 < upto){
		loopR3(R2, upto);
		R2++;
	}
}
void loopR3(int R3, int upto)
{
	int R1 = 1;
	int R2 = 1;
	while (R3 < upto){
		printf("%d\t %d\t %d\t payoff is %d\n", R1, R2, R3, payoff(R1, R2, R3));
		R3++;
		loopR3(R3, upto);
	}
}

/////////////////////////////////////////////////////////
//FUNCTIONS:
/////////////////////////////////////////////////////////
int payoff(int R1, int R2, int R3) {
	if (R2 < R1) {
		total = total + R2;
	} //end if
	else {
		if (R3 < R1) {
			total = total + R3;
		} //end if
		else {
			total = R1;
		} // end else
	} //end else


	if (R3 < R2) {
		total = total + (2 * R3);
	} //end if
	else {
		if (R3 < R1) {
			total = total + R3;
		} //end if
		else {
			total = R1;
		} //end else
	} //end else

	return total;
} //end function payoff 



My out put for R1, R2 and total are always 1 except for R3 which actually increments. The desired out put I want is for it to be something like this:


1 1 1 payoff is 1
1 1 2 payoff is 1
//...some iterations later
3 3 1 payoff is 4
3 3 2 payoff is 5
3 3 3 payoff is 3


Can anyone help me figure out why R1 and R2 never change as well as total? Many thanks in advance.
Topic archived. No new replies allowed.