@BlueRyse
Here are some ideas to consider about your code:
* Each case in the switch should call a function, that function should return a value
* Provide a Quit case in the switch. Make it operate on a bool variable:
1 2 3 4 5 6 7 8 9 10
|
bool Quit = false;
while (!Quit) {
// switch
// other cases
case 3:
Quit = true;
std::cout << "Grazie e arrivederci!\n";
break;
}
|
That way you could avoid the infinite loops, the do loops, and the goto. It will also make the code easier to read. The
return 0;
is a bit drastic - it ends the program, this way you can provide a sane end to the loop. You could also do away with the
do {} while(b);
in each case.
Try to avoid using
goto
, unless you know what you are doing. I am not saying goto should be banned, there are valid uses for it. But it is something beginners should avoid, this is an example where it can be avoided.
Having a
break;
after each case is normal practise for switch statements, unless one wants it to fall through each case on purpose.
You could also have a function for validation: Lines 22 to 28 and 43 to 49 are very similar. If you find yourself writing the same code over and over, then write a function.
Prefer
double
over float, the latter precision is easily exceeded.
With the variables, choose meaningful names, don't abbreviate everything to a single char identifier. Ideally wait until you have a sensible value to assign, then do declaration and assignment all on 1 line. Do 1 variable per line.
Variables like y should be const:
const double y InchesToCm - 2.54;
Finally, try to avoid
using namespace std;
There is lots written about this - Google / wiki it :+)