Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions