I am trying to create a counter. It counts each operation such as multiplication, addition, subtraction, division. Every time I try to cout the counter, it stays as zero.
Can anyone shed any light on what I am doing wrong?
A bulk of my code is missing so I can protect it from other classmates, however I have listed how many operations is in that section where the code would be.
long karatsuba(int num1, int num2, int &counter)
{
if (num1 < 10 || num2 < 10)
{
counter++ // 1 operation
return num1 * num2;
}
/* calculates the size of the number */
... 4 operations
/* split the digit sequences about the middle */
... 4 operations
/* 3 calls made to numbers approximately half the size */
int z0 = karatsuba(..., ..., counter);
int z1 = karatsuba(..., ..., counter);
int z2 = karatsuba(..., ..., counter);
return ... // 9 operations
}
-------------------------------------------------------------
int main()
{
int counter = 0;
cout << karatsuba(123, 456, counter) << " " << counter << endl;
cout << endl;
system("Pause");
return 0;
}