ā” 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
Honza K.
Honza K.•2y ago
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
new TimeSpan(hoursValue, minutesValue, 0).Add(TimeSpan.FromMinutes(minutesToAddValue));
new TimeSpan(hoursValue, minutesValue, 0).Add(TimeSpan.FromMinutes(minutesToAddValue));
šŸ˜„
Pobiega
Pobiega•2y ago
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 ?
GlitchYourDevice
GlitchYourDeviceOP•2y ago
no i dont but i have the answer to the promblem but i just dont understand the answer here is the answer
GlitchYourDevice
GlitchYourDeviceOP•2y ago
Pobiega
Pobiega•2y ago
What part do you not understand?
GlitchYourDevice
GlitchYourDeviceOP•2y ago
can somone please explain the answer to me i dont understand the modelus becuase i have not used it before
ThatDaniel
ThatDaniel•2y ago
% returns the remainder, eg. if hours is 25 then 25 % 24 would be 1
Pobiega
Pobiega•2y ago
% is the "remainder" operator
Honza K.
Honza K.•2y ago
the % 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
GlitchYourDevice
GlitchYourDeviceOP•2y ago
why m += antalMinuter % 60?
Pobiega
Pobiega•2y ago
lets say antalMinuter is 62
GlitchYourDevice
GlitchYourDeviceOP•2y ago
ok
Pobiega
Pobiega•2y ago
62 / 60 = 1, so we add 1 hour 62 % 60 is 2, so we add 2 minutes
ThatDaniel
ThatDaniel•2y ago
tbh line 9 does not need the % as the minutes undergoes % again at line 12, it could just do the add m += antalMinuter
Accord
Accord•2y ago
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.

Did you find this page helpful?