### 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.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980`` `````` #include //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.