There are a few things I can see here:
Here is a better way of exiting out a loop (It was something I did to help someone else):
You have lots of these:
while (rerun2 == 'y' || rerun2 == 'y');
I think you meant to have one of those capitalised, but my code above shows a better way to do this.
I prefer not to use do loops unless I really have to - which is rare.
Next is code using doubles like this:
if (a2 - a1 == a3 - a2)
This will almost certainly evaluate to false. Consider this:
1 2 3 4 5
|
float a = 0.1; // a == 0.09999997
float b = 10 * a; // b == 0.9999997
if(a == b) // false
|
Changing the type to double doesn't help.
This is because floating point numbers (floats & doubles) are stored as binary fractions, and cannot represent every real number.
To fix this, you can have a variable which is the precision that you require:
double MyPrecision = 0.001
Then, if you want to check the equality of variable a & b, check that the absolute value of a- b is less than MyPrecision.
The next thing is to make use of functions. Printing the menu should be a function. Instead of having a lot of if else statements, you can use a switch statement. Each case of the switch should call a function that carries out that menu option.
Hope all goes well.