I'm new to programming and I have been messing around with a bit of C++. I have a simple program that works, but I have a lot of similar functions that I want to get rid of. I figured I would just use a function for it and add parameters that I can change, but in an if-statement I have the function call itself back so it could run the same function again.
So my question trying to find a work around so I can simplify the similar functions. In the code I have provided there are only a few differences between function 1 and 2. In my actual program I have about 8 of these similar functions.
int a;
// function 1
int ba = 0;
int bb = 0;
int bc;
// function 2
int ca = 0;
int cb = 0;
int cc;
void function2() {
cin >> a;
if(a == 1) {
ca = ca + 10000;
cb = cb + 100;
function2();
}
if(a == 0) {
cb = cb + 100;
function2();
} else {
cc = ca / cb;
}
}
void function1() {
cin >> a;
if(a == 1) {
ba = ba + 10000;
bb = bb + 100;
function1();
}
if(a == 0) {
bb = bb + 100;
function1();
} else {
bc = ba / bb;
}
}
int main() {
function1();
function2();
}