Question: Your task is to write a MATLAB script that asks (in two separate questions) the user what type of fruit they would like to buy,

Your task is to write a MATLAB script that asks (in two separate questions) the user what type of fruit they would like to buy, and how many. It then reports the total cost. The table for available fruits and their prices is as follows:

Fruit Price Apple $0.85 Banana $0.29

In order to receive full credit, the program must have the following properties:

1. The program must recognize the fruits regardless of how the input is capitalized, so banana, BAnaNa, and baNANA should all be interpreted as banana.

2. On any other input for the fruit, the program should complain that it doesnt recognize the fruit and then assume that the user wants apples.

3. If the number requested is negative or not an integer, the program should again complain and then assume the user wants 3 fruit.

4. The report to the user should take the form Okay, N FRUIT TYPE will cost you $PRICE. using fprintf.

5. No other computations done during the program should be displayed (i.e. use semicolons).

6. The program should have some comments describing how it works.

Tips:

The function (strcmpi) will be handy for determining the fruit ordered.

round(x) will round a number to the nearest integer, so will be handy in testing whether x is an integer.

Example runs of a correctly written program include the following:

>> hw1 What kind of fruit would you like? bANAna

How many would you like? 7

7 bananas will cost you $2.03

>> hw1 What kind of fruit would you like? bananas

Sounds to me like you want apples.

How many would you like? sqrt(8)

I think you want three fruit

3 apples will cost you $2.55

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!