3) Pseudo-code is where you write out the correct English-like statements but ar
ID: 3563723 • Letter: 3
Question
3) Pseudo-code is where you write out the correct English-like statements but are not worrying about the MATLAB syntax being exactly correct. For example, a file called setPrice.m in MATLAB might look like this in pseudo-code:
Input price
if (cents < 0)
print "Illegal price"
else
price = cents
print "price set to" + price + "cents"
Notice how much of this pseudo-code would not work if plugged into MATLAB. This is fine! The whole idea is to create a very basic outline of the code, and you can worry about the syntax when you implement the function.
Let
Explanation / Answer
quarters=0
dmes=0
nickels=0
pennies=0
input total
input cost
change=total-cost
// assuming the unit is dollar, convert it to cents
change=change*100
while change > 25
change=change-25;
quarters++;
end
if change==0
print "number of quarters : " + quarters
print "number of dimes: "+ dimes
print "number of nickels: "+ nickels
print "number of pennies: "+ pennies
exit
end
while change>10
change=change-10;
dimes++;
end
if change==0
print "number of quarters : " + quarters
print "number of dimes: "+ dimes
print "number of nickels: "+ nickels
print "number of pennies: "+ pennies
exit
end
while change >5
change=change-5;
nickels++;
end
if change==0
print "number of quarters : " + quarters
print "number of dimes: "+ dimes
print "number of nickels: "+ nickels
print "number of pennies: "+ pennies
exit
end
while change >=1
change=change-1;
pennies++;
end
if change==0
print "number of quarters : " + quarters
print "number of dimes: "+ dimes
print "number of nickels: "+ nickels
print "number of pennies: "+ pennies
exit
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.