Question: Create a single script (.m file) to solve this problem. Unless directed otherwise, use meaningful variable names for each variable; do not use the default

Create a single script (.m file) to solve this problem. Unless directed otherwise, use meaningful variable names for each variable; do not use the default variable ans to store your results. For this project, suppress your output with semi-colons (;). Each problem should be in a separate cell, using the cell mode feature of MATLAB

Problem 2:

It is often important to validate if the user entered an acceptable input to a program. For this problem, you may safely assume that the user only enters numeric inputs (i.e. do not consider the case where the user inadvertently enters letters instead of numbers). Emulate the output format below; your code should print the output exactly as shown in the sample runs.

Prompt the user to enter a number of days, to enter a number of hours, to enter a number of minutes, and to enter a number of seconds. Print the values that the user entered to the Command Window. You may assume the user will only enter positive integers.

Consider the following maximums:

The user enters more hours than the maximum of 24 hours in a day

The user enters more than minutes than the maximum of 60 minutes in an hour

The user enters more seconds the the maximum of 60 seconds in a minute

If the users input exceeds any, some, or all of these maximums, correct their values so that they do not exceed the maximum. As a numeric example, if the user enters 2 days, 30 hours, 62 minutes, and 62 seconds, the program should store the data as 3 days, 7 hours, 3 minutes, and 2 seconds. Only use techniques discussed in class to perform the correction (i.e. do not look up alternative built-in MATLAB approaches to perform the correction. The number of days does not need to be constrained (i.e. do not worry about years).

Test to see if any correction was made to any of the users inputs. If there was a correction to any of the values the user entered, print the statement The user-entered values required correction. If there was not a correction, print the statement The user-entered values required no correction. Furthermore, if the values were corrected, print the corrected values

Sample Run #1:

Enter the number of days: 2

Enter the number of hours: 22

Enter the number of minutes: 45

Enter the number of seconds: 30

The user entered 2 days, 22 hours, 45 minutes, and 30 seconds.

The user-entered values required no correction.

Sample Run #2:

Enter the number of days: 2

Enter the number of hours: 30

Enter the number of minutes: 62

Enter the number of seconds: 62

The user entered 2 days, 30 hours, 62 minutes, and 62 seconds.

The user-entered values required correction. The new values are: 3 days, 7 hours, 3 minutes, and 2 seconds.

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!