USING MATLAB
get_coin_value(‘q’)
You should see the number 25 pop up. To try with other coins, change the ‘q’ to ‘d’,’n’ or ‘p’. Also try replacing the ‘q’ with ‘not a coin’. A zero should be displayed when an invalid coin is entered.
function get_coin_value(coin)
value = 0;
# if else statment to set value as per passed parameter
if coin == 'q'
value = 25;
elseif coin == 'd'
value = 10;
elseif coin == 'n'
value = 5;
elseif coin == 'p'
value = 1;
else
value = 0;
endif
disp(value); # print the value
endfunction
Get Answers For Free
Most questions answered within 1 hours.