Q:

Write a function nexthour that receives one integer argument, which is an hour of the day, and returns the next hour. This assumes a 12- hour clock; so, for example, the next hour after 12 would be 1. Here are two examples of calling this function

0

 Write a function nexthour that receives one integer argument, which is an hour of the day, and returns the next hour. This assumes a 12- hour clock; so, for example, the next hour after 12 would be 1. Here are two examples of calling this function.

>> fprintf('The next hour will be %d.\n',nexthour(3))

The next hour will be 4.

>> fprintf('The next hour will be %d.\n',nexthour(12))

The next hour will be 1. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

 nexthour.m

function outhour = nexthour(currenthour)

% Receives an integer hour of the day and 

% returns the next integer hour

% Format of call: nexthour(hour of day)

% Returns the next integer hour

outhour = currenthour + 1;

if outhour == 13

 outhour = 1;

end

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now