% MT 03 2018/19 % Problem Set 2, Exercise 2 E_in = input('Enter the value of the energy converted: '); E_in_units = input('Enter the current units (J, cal, eV): ', 's'); E_out_units = input('Enter the new units (J, cal, eV): ', 's'); error = 0; switch E_in_units case 'J' EJ = E_in; case 'cal' EJ = E_in / 0.239; case 'eV' EJ = E_in / 6.24e18; otherwise error = 1; end switch E_out_units case 'J' E_out = EJ; case 'cal' E_out = EJ * 0.239; case 'eV' E_out = EJ * 6.24e18; otherwise error = 1; end if error disp('Error! Current or new units typed incorrectly'); else fprintf('E = %g %s \n', E_out, E_out_units); end