ā exercise without datetime
Write a program (without using DateTime) where the user can enter a time in a form
of two numbers, hours (0-23) and minutes (0-59). There, the user can enter a third number (i
minutes of unlimited size) to be added to the current time. The program will then
display the new time correctly in hh:mm format.
15 Replies
no days? if you go over 24hrs, you just go back to 00:00 without counting the "resets"?
if so, then I'd just do
š
I'm guessing if
DateTime
is not allowed, TimeSpan
shouldn't be either :p
But yeah, this isnt very hard tbh. Do you know how classes work @GlitchYourDevice ?no i dont but i have the answer to the promblem but i just dont understand the answer
here is the answer
What part do you not understand?
can somone please explain the answer to me i dont understand the modelus becuase i have not used it before
% returns the remainder, eg. if hours is 25 then 25 % 24 would be 1
%
is the "remainder" operatorthe % operator gives you whatever's left from the division, like if you divide 10/4 it's 2,5 so 10 % 4 gives you 5
why m += antalMinuter % 60?
lets say
antalMinuter
is 62ok
62 / 60 = 1, so we add 1 hour
62 % 60 is 2, so we add 2 minutes
tbh line 9 does not need the % as the minutes undergoes % again at line 12, it could just do the add
m += antalMinuter
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.