In: Computer Science
USING MATLAB
Part 2: Insert coins
For this part, you are going implement the code that asks the user to enter coins until they have entered enough for the NAU power juice.
Note: I am showing the full working code below. If some part is already implemented for you, substitute that part accordingly into this code. If any confusion, please let me know in the comments.
Matlab Code:
total = 0;
%Following function to return the value as per coin name
function value = get_coin_value(c)
c = lower(c); %converting input to all lowercase
if strcmp(c,"penny") == 1
value = 1;
elseif strcmp(c,"nickel") == 1
value = 5;
elseif strcmp(c,"dime") == 1
value = 10;
elseif strcmp(c,"quarter") == 1
value = 25;
elseif strcmp(c,"half") == 1
value = 50;
elseif strcmp(c,"dollar") == 1
value = 100;
end
end
%Loop to keep asking user for coin till total is less than 115
cents
while(total<115)
coin = input("Please enter a coin: ",'s');
total = total + get_coin_value(coin);
end
disp("Your NAU power juice has been dispensed")
Sample Output Screenshot:
(*Note: Please up-vote. If any doubt, please let me know in the comments)