Look at the description of
std::map
at the Reference section.
Lets make a simpler table:
tn 1e+6
kg 1000.0
lb 453.6
oz 28.4
g 1.0 |
You do get input amount and unit.
You can look up the unit from the table. If the input is not in the table, then it is invalid. Use a while-loop to get valid input. Do not use
goto
. While 'goto' may appear "simple", it actually makes program more complex and error-prone.
Now you have a valid unit. The table has a corresponding value. If you do multiply the amount with the value, you do perform a conversion to what unit?
Then you have the output unit and its corresponding value. If you divide the result of previous multiplication with the output-value, you again convert the unit. From what to what?
It is an extra optimization to handle the input==output non-conversions.
Why do you print the std::strings as C-strings?