write a function that takes a total value of change and returns the correct number of dollars, quarters, dimes, nickels, and pennies using as many of the higher valued coins in matlab in matlab

main.m
function changeBreakdown(total)
    dollars = floor(total);
    remaining = total - dollars;
    
    quarters = floor(remaining / 0.25);
    remaining = remaining - (quarters * 0.25);
    
    dimes = floor(remaining / 0.1);
    remaining = remaining - (dimes * 0.1);
    
    nickels = floor(remaining / 0.05);
    remaining = remaining - (nickels * 0.05);
    
    pennies = remaining * 100;
    
    fprintf('Dollars: %d\nQuarters: %d\nDimes: %d\nNickels: %d\nPennies: %d\n', dollars, quarters, dimes, nickels, pennies);
end
529 chars
18 lines

related categories

gistlibby LogSnag