This is my first post to the forum, so apologies if it's in the wrong forum or even a useless question, but I've only been coding for about a week and I was wondering if I made any unnecessary lines or if anything could be improved as I'm still getting the feel of it. Thanks!
The biggest one is to not try and cope with every or some of the combinations of words: "Add""addition""Addition", what if the user types aDdition Instead stick to options which are a single char or number in a menu.
Integer math doesn't work well for this, especially division, change the type to double
When doing division, always check for division by zero. With double this is a little trickier: We need to check if the absolute value of the number is less than some arbitrary precision value, because doubles are not stored exactly.
1 2 3 4 5 6 7 8 9 10
constdouble Precision = 0.001;
double a = 0.1; // really 0.1 +/- 3e-16 say
double b = 1.0 - (10.0 * a); // not zero, +/- 3e-15 say
if(std::abs(b) < Precision ) {
std::cout << "b is near enough to zero (< 0.001)\n";
} else {
std::cout << "b is not zero \n";
}