Concept explainers
To write:
An “if” statement that would print “Hey, you get overtime!” if the value of a variable hours is greater than 40. Test the “if” statement for values of hours less than, equal to, and greater than 40.
Answer to Problem 4.1P
Solution:
Print the statement “Hey, you get overtime!” if the value of the variable time is greater than 40.
Explanation of Solution
MATLAB Code:
clc
clear all
close all
Variable_Time_in_Hours = input('Enter Variable Time in Hours: ');
% Define the instruction to enter the variable time in hours.
if Variable_Time_in_Hours > 40
% Define the instruction to get the variable time in hours greater than 40.
fprintf('Hey, you get overtime!\n');
% Define the command to generate the statement "Hey, you get overtime!".
end
Save the MATLAB script with name, chapter4_54793_4_1P.m in the current folder. Execute the script by typing the script name at the command window to write an “if” statement that would print “Hey, you get overtime!” if the value of a variable hours is greater than 40. Test the “if” statement for values of hours less than, equal to, and greater than 40.
Result:
Therefore, print the statement “Hey, you get overtime!” if the value of the variable time is greater than 40.
Want to see more full solutions like this?
Chapter 4 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Glencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw HillAlgebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal LittellHolt Mcdougal Larson Pre-algebra: Student Edition...AlgebraISBN:9780547587776Author:HOLT MCDOUGALPublisher:HOLT MCDOUGAL