Question

using matlab, write a script for the following that prompts the user to input the amount...

using matlab, write a script for the following that prompts the user to input the amount of cases bought as a vector, calculates the cost, and stores the correspondind cost in a row beneath the demand:

the price of produce is calculated as follows:

if 30 cases of oranges are bought, the cost is 4 dollars per case

if more than 30, but less than 100 cases are bought, the cost is 10 for the first 30 cases, then 3 dollars for every case in excess of 30.

if more than 100 cases are bought, the cost is 5 dollars for the first 100 cases bought plus 1 dollar for every case in excess of 100.

a basic fee of 2 dollars is charged regardless of how many cases are bought.


0 0
Add a comment Improve this question Transcribed image text
Answer #1
cases = zeros(2, 1); % 2x1 marix first row contains demand and second row contains cost
cases(1) = input('Enter amount of cases bought');

cost = 0;
if cases(1) > 100
    cost = 5*100; % 5 dollar per case for first 100 cases
    cost = cost + 1*(cases(1) - 100); % 1 dollar for every case in excess 100
elseif cases(1) > 30
    cost = 10*30; % 10 dollar per case for first 30 cases
    cost = cost + 3*(cases(1) - 30); % 3 dollar for every case in excess 30
elseif cases(1) == 30
    cost = 4*cases(1); % the cost is 4 dollars per case
end
cost = cost + 2; % 2 dollars charged regardless of number of cases bought

cases(2) = cost; % Store in row beneath the demand

SAMPLE OUTPUT:

COMMAND WINDOW >>final Enter amount of cases bought >> cases Cases 377

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
using matlab, write a script for the following that prompts the user to input the amount...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a script in matlab that prompts the user to input the day, month, and year;...

    Write a script in matlab that prompts the user to input the day, month, and year; determine the day of the year (the number of days including the current day). Be sure to take leap year into account. Use a for loop Test your code on the following dates: February 28, 2015 April 9, 1976 October 12, 1887 Create a script that performs the same function as repmat. The only built-in commands you may use are input, size, and disp.

  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • Please write the script for following problem in MATLAB. Write a script with a file name...

    Please write the script for following problem in MATLAB. Write a script with a file name Problem3.m that, when executed, prints 1.99 dollars per unit. How many units will you purchase? [new line] Then control is given back to the user to input a scalar integer quantity. The script then prints out __ units at 1.99 dollars per unit is a total of ___ dollars. [new line] where the first blank is filled with whatever number was inputted by the...

  • MATLAB homework assignment (HW6), but this time using a "vectorized" approach. Write a script that prompts...

    MATLAB homework assignment (HW6), but this time using a "vectorized" approach. Write a script that prompts the user for N integers (set N-6), one at a time, using a while loop. Error-check to ensure that each number entered is an integer, displaying an error message if it is not. If it is an integer, store it in an array variable nums. Continue prompting until N integers have been successfully entered. (You may copy and paste your code from the previous...

  • Write a script called makeChange that prompts the user for a monetary amount in cents less...

    Write a script called makeChange that prompts the user for a monetary amount in cents less than or equal to 99 cents (i.e. less than a loonie) and then prints how change would be made for that amount out of quarters (25-cent coins), dimes (10-cent coins), nickels (5-cent coins) and pennies (1-cent coins). The change your script specifies should be the minimum number of coins. For example, when making change for 88 cents, the result should indicate 3 quarters, 1...

  • Write a script that prompts the user to enter a value n (n > 6) that...

    Write a script that prompts the user to enter a value n (n > 6) that will generate an n element vector of random integers between 0 and 100 that will represent quiz grades. Then have the script calculate the average of the quizzes where the smallest grade is dropped. Then script will display the average of the quizzes along with the highest quiz grade. Given the following system of equations: 8s - 11t + 7u + 5v - w...

  • Can you make matlab solve it? 3. The electricity accounts of residents in a very small...

    Can you make matlab solve it? 3. The electricity accounts of residents in a very small town are calculated as follows: e if 500 units or less are used the cost is 2 cents per unit; . if more than 500, but not more than 1000 units are used, the cost is $10 for the first 500 units, and then 5 cents for every unit in excess of 500; . if more than 1000 units are used, the cost is...

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

  • answer 4, 5, 6, 7 using matlab Homework 10 1. Write the correct first-line syntax for...

    answer 4, 5, 6, 7 using matlab Homework 10 1. Write the correct first-line syntax for a user defined function that is named Feynman and has input variables q and e, and outputs L and M. (Comment out of this line). 2. Using zeros, ones, and eye commands write the one line syntax to create the following matrix: 00000 01100 01010 01001 3. Write the syntax for the user defined function that calculates the surface area and volume of a...

  • Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a...

    Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the name and the price per unit for two different candies. Then, the customer is allowed to order as many units of each of the two candies as they would like. Lastly, an invoice (report) is generated (displayed to the screen) under the following rules: All units up to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT