I am currently going through professor Stroustrup book: "Programming principles and practice, 2 nd ed.".
It is a task from Chapter 5, task 5 - Write a Celsius to Kelvin (and reverse) calculator, paying attention to bad input and impossible temp values.
Code works, but I wanted to ask you for a code review.
1. Is everything done in a proper way?
2. Is it a proper way of dealing with bad input? How do professionals deal with bad input? (you can give me even some advanced ideas, I will just come back to them later on)
I would use better function names like CelciusToKelvin().
Also I would use better error texts like "Celcius must not be smaller than -273.15.
Finally when promping for the input you might give the valid range
YOu really need to convert the menu_choice to lower case, if you're going for clean input. If the user for whatever reason enters a capital letter, they will get invalid choice. That's not totally professional. try adding this
while ((menu_choice!='k') && (menu_choice!='c') && (menu_choice!='q'))
why did I add Q? How does the user end the program? What clue is the user given to exit the program? Professionally speaking - you need to give them a way to voluntarily quit the program without entering something random.
Also, if the menu choices were integer, you could move your cin into the while statement to protect from users entering letters instead of numbers and breaking your program.