Question

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 user, and the second blank is the total cost of all the units, rounded to the nearest cent. For example:

>>Problem3

1.99 dollars per unit. How many units will you purchase? 5

5 units at 1.99 dollars per unit is a total of 9.95 dollars.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

% prompt the input information about price to the user
% Take the number of units as the input
units = input('1.99 dollars per unit. How many units will you purchase? ');

% define the per unit price for the item
per_unit_price = 1.99;

% calculate the total price based on the number
% of units entered by the user
total_price = units * 1.99;

% make it to the nearest cent
total_price_nearest_cent = ceil(total_price*100)/100;

% print the final price to the user with number of units
fprintf("\n%d units at 1.99 dollars per unit is a total of %.2f dollars.\n", units, total_price_nearest_cent);

Screenshot of the output:

1.99 dollars per unit. How m 5 units at 1.99 dollars per unit is a total of 9.95 dollars.

Add a comment
Know the answer?
Add Answer to:
Please write the script for following problem in MATLAB. Write a script with a file name...
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
  • matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that...

    matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that will print a menu consisting of "Cylinder," "Circle," and "Rectangle." It waits for the user to choose from the menu then call the corresponding function of each choice as follows: 1- Cylinder will call the function (cyl) which prompts the user for the radius and height of the cylinder, then calculates and prints area of the cylinder. 2- Circle will call the function (cir)...

  • Write a Matlab script to complete the following: 1. Write a script file that allows a...

    Write a Matlab script to complete the following: 1. Write a script file that allows a user to: a. Plot a function from a list b. Change the function coefficients c. Choose function range and number of points d. Replot a new function on the same graph keeping the original function e. Replot a new function on the same graph overwriting the original function f. Save the graph (as a png file) Functions to choose from: y A sin(Bx +...

  • MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when c...

    MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when called, it gives control to the user and asks the user to input a length-3 vector. Then the function prints: The sum of ___, ____, and ____ is ____. [new line] where the first three blanks are filled by each element in input vector, and the last blank is the sum of all three elements.

  • USING MATLAB Write a script that asks the user to input a sentence. It then replaces...

    USING MATLAB Write a script that asks the user to input a sentence. It then replaces all instance of 'he', 'she', 'He', or 'She' with 'Mr. Meseeks' and prints out the new sentence. . HINT: Use 'strrep' and 'lower' function.

  • Write a matlab script(using only matlab) for this. Write a script to solve the following problem:...

    Write a matlab script(using only matlab) for this. Write a script to solve the following problem: Ask the user for the length and the width of a rectangle. These need to be passed to a function. The function is to calculate and return the area and the perimeter of the rectangle. The area is the length times the width and the perimeter is 2 times the length and 2 times the width. Make sure to suppress all output from the...

  • Please help with this code For the following problem write a Matlab® script file with clear...

    Please help with this code For the following problem write a Matlab® script file with clear commentary for each line of code. Your script should: Load the data in the problem as a text file. Calculate the statistics using Matlab  functions. Solicit input from the user of the reading (for example, 137 degrees as stated in the problem). In another word, the reading should not be fixed in the script and has to be entered and saved from the command window...

  • Please Answer Quickly Quantity discount program Write a MATLAB program that takes two inputs from the...

    Please Answer Quickly Quantity discount program Write a MATLAB program that takes two inputs from the user, Input 1: a decimal number that is a unit price (the price of one item) in dollars and cents Input 2: an integer that is the quantity of the item to purchase. The program prints 3 outputs, each on its own line: output 1: the total cost with no discount (unit price X quantity) output 2: the amount of discount in dollars and...

  • Please show in MATLAB code using if and else statements if necessary Write a program in a script ...

    Please show in MATLAB code using if and else statements if necessary Write a program in a script file that converts a quantity of energy given in units of either J (Joules), Btu, or (ft-lb) to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of power in the new units using the fprintf command....

  • Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations:...

    Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations: Prompt the user to enter an integer. Use a multiple if-elseif structure to determine the following: Confirm that the number is an integer. If not, the program displays message 1. Check if the number is divisible by 2 and displays message 2. Check if the number is divisible by 3 and displays message 3. For anything other than 1, 2, or 3, the program...

  • 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...

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