Your function
subtractfunction is given a
copy of the variables. Anything it does, it does to the
copy. When the function ends, those copies are discarded. The originals, from your main function, are unchanged.
Try passing the variables by reference, so that the functions don't get copies but instead work on the originals.
This is done by adding the & symbol in the function declaration and definition, like this:
1 2
|
void subtractfunction(int& oscillate, int& denominator, int& totalpi);
void additionfunction(int& oscillate, int& denominator, int& totalpi);
|
and similarly in the defintions (line 30 and 35).
I suggest also that since you're going to be working with numbers that aren't integers, you don't use
int for your numbers. Making totalpi an integer seems silly when you know it's meant to end up 3.14159; how can you represent 3.14159 with an integer?
Note also that in C++, an int divided by an int gives an int (line 31, line 36). Here's a clue to help fix that.
1/2 = 0
1/2.0 = 0.5