Also, don't use
goto
, use loops and function instead. Most of lthe code in lines 77 to 196 could be replaced by one short function, which could be called from each of the
case
s in the
switch
.
Functions should be fairly short (say 20 LOC or less), including the
main
function.
Also, don't have global variables, they can cause awkward problems.
There is also a convention to put declarations of the functions before main, then the main function, then the function definitions. This is so the main function is near the top of the file, which makes it easier to read.
Check for divide by zero, before you do the division. If the type is a
double
, check if the value is less than some constant precision value. For example if the number is less than say 0.000001, then it is near enough to zero for our purposes.
1 2 3 4 5 6 7
|
const double Precision = 1e-6;
double a = 1e-7;
if (a < Precision) { // a is near enough to zero
// print error mesg
}
|
The output could be a function of it's own, rather than repeatedly writing the same std::cout statement.
Good Luck !!