1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
hjlf
3 years ago
15

Write a function [change,flag] = makeChangeRecursive(cost,paid) that takes the cost of an item cost (a 1x1 double) and the amoun

t paid by the buyer paid (a 1x1 double), and returns a n x 1 column array of doubles change containing the bills that the seller should give back to the buyer in decreasing order and flag a 1x1 logical true or false saying whether the transaction was "completed". If paid is less than cost, flagis false and you should display a warning in the command window saying "That's not enough to buy that item." and change is assigned as an empty array. If cost and paid are equal the change is assigned as an empty array and flag is true. If paid is greater than cost, flag is true and change is the difference between the two made by combining the denominations: 100, 50, 20, 10, 5, 2, and 1.
Computers and Technology
1 answer:
vaieri [72.5K]3 years ago
5 0

Answer:

The answer to this question can be given as:

function [change,flag]=makeChangeRecursive(cost,paid)          

//define function

change=[];    

flag=false;                  //use flag for true or false.

if((paid-cost)>=100)         //checking condition value greater then equal to 100

[m,f]=makeChangeRecursive(cost,paid-100);

change=[100;m];

flag=true;

return;

elseif((paid-cost)>=50)     //checking condition value greater then equal to 50

[m,f]=makeChangeRecursive(cost,paid-50);       //holding value.

change=[50;m];    

flag=true;

return;

elseif((paid-cost)>=20)    //checking condition value greater then equal to 20

[m,f]=makeChangeRecursive(cost,paid-20);

change=[20;m];

flag=true;

return;

elseif((paid-cost)>=10)      //checking condition value greater then equal to 10

[m,f]=makeChangeRecursive(cost,paid-10);

change=[10;m];

flag=true;

return;

elseif((paid-cost)>=5)         //checking condition value greater then equal to 5

[m,f]=makeChangeRecursive(cost,paid-5);

change=[5;m];    

flag=true;

return;

elseif((paid-cost)>=2)   //checking condition value greater then equal to 2

[m,f]=makeChangeRecursive(cost,paid-2);

change=[2;m];

flag=true;

return;

elseif((paid-cost)>=1)  //checking condition value greater then equal to 1

[m,f]=makeChangeRecursive(cost,paid-1);

change=[1;m];    

flag=true;

return;

elseif((paid-cost)<0)                        //checking condition value less then 0

warning('That''s not enough to but an item.');         //print message

flag=false;

return;

elseif(paid==cost)               //checking condition if value is equal.

flag=1;                                   //falg value.

change=[];

return;    

end                              

end        //end function

Explanation:

In the above program code the function must use the recursion to change the variable.This function run in 4 case i.e. case 1  In this case when we pass the  value [change,flag]=makeChangeRecursive(2,100) in the function so the change value will be 50,20,20,5,2,1,and flag= ,1. In case 2 when we pass the value(3,20) in the function so the change value will be 10,5,2,and flag= ,1. In case 3 when we pass the value(20,20) in the function so the change value will be change= {},flag= 1. In case 4 when we pass the value(59,20) in the function so the change value will be warning message i.e That''s not enough to but an item.

You might be interested in
Brenda wants to finish her presentation with a summary slide . She wants three key messages to appear on each of the photo clips
Sav [38]

Brenda can first include an image and then include text. Lastly she can just provide an enhanced effect to the text to appear one by one each photo clip.

4 0
3 years ago
Read 2 more answers
Your principal has hired you to design a drone that can monitor students in the hallways. Before you brainstorm design ideas, yo
torisob [31]
It’s gonna be Answer B because all the other answers just sound silly
8 0
3 years ago
Read 2 more answers
How to make text icome one word at a timen filmora
bezimeni [28]

You would want to add multiple text slides.

I hope this helps as the wording of the question was unclear.

8 0
2 years ago
Use a VLOOKUP function in cell I5 to identify and calculate the federal withholding tax. Use the tax rates from the range D21:E2
SVEN [57.7K]
In the Cell 'H13' of Sheet 'Payroll Data', the 'Formula' was not set to 'G13-B13*$B$24'.
6 0
3 years ago
Downlad the file and write a program named Lab10b_Act2.py that does the following: Opens the CSV file for reading Reads the CSV
a_sh-v [17]
他們會不會是因為這樣就是說他們的問題,他們會會覺得委屈覺得我
5 0
2 years ago
Other questions:
  • What is Least effective at preventing a computer virus
    10·1 answer
  • This information is generally included on a fax cover sheet.
    15·1 answer
  • The code segmentif (speed &lt;= 40)cout &lt;&lt; "Too slow";if (speed &gt; 40 &amp;&amp; speed &lt;= 55)cout &lt;&lt; "Good spee
    11·1 answer
  • Yolanda lost her left foot during her military service, but she has been issued a prosthetic that enables her to walk normally,
    13·1 answer
  • A(n) _____ measures the ability to juggle a variety of demands, as in a manager's job where the candidate is presented with simu
    8·1 answer
  • Your boss is very skeptical about the idea of storing his files up in the cloud rather than on a local storage drive. He asks yo
    7·1 answer
  • Quinton is having trouble learning Spanish because he keeps reverting back to the grammatical structures of his native English l
    6·1 answer
  • Tom Daniels, an employee of a telecommunications company, is developing software that would enable customers to activate value-a
    7·1 answer
  • write a script that creates and calls a stored procedure named insert_category. first, code a statement that creates a procedure
    10·1 answer
  • What is wrong with my code...
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!