C
C#ā€¢13mo ago
GlitchYourDevice

ā” 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.ā€¢13mo 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ā€¢13mo 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
GlitchYourDeviceā€¢13mo ago
no i dont but i have the answer to the promblem but i just dont understand the answer here is the answer
GlitchYourDevice
GlitchYourDeviceā€¢13mo ago
Pobiega
Pobiegaā€¢13mo ago
What part do you not understand?
GlitchYourDevice
GlitchYourDeviceā€¢13mo ago
can somone please explain the answer to me i dont understand the modelus becuase i have not used it before
ThatDaniel
ThatDanielā€¢13mo ago
% returns the remainder, eg. if hours is 25 then 25 % 24 would be 1
Pobiega
Pobiegaā€¢13mo ago
% is the "remainder" operator
Honza K.
Honza K.ā€¢13mo 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
GlitchYourDeviceā€¢13mo ago
why m += antalMinuter % 60?
Pobiega
Pobiegaā€¢13mo ago
lets say antalMinuter is 62
GlitchYourDevice
GlitchYourDeviceā€¢13mo ago
ok
Pobiega
Pobiegaā€¢13mo ago
62 / 60 = 1, so we add 1 hour 62 % 60 is 2, so we add 2 minutes
ThatDaniel
ThatDanielā€¢13mo 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ā€¢13mo 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.
Want results from more Discord servers?
Add your server
More Posts
ā” Needs some help with setting Webview2 option and fixing a known bugSome background info: I built an app that is currently in production that is pretty much a full screā” Getting started with C#I'm trying to get started with C# but don't know where to start can somebody help me help me out Thaā” Filling RDLC report table with a custom SQL query.How can I fill an RDLC report table from a custom sql query that gets data from several tables? I tāœ… Question about Youtube tutorials to learn C#Im learning C# and I would like to know what videos/video series you'd recommend a beginner to watchā” Question.I'm wondering how to remove all past text in my code.ā” Question on how AddDbContext worksI have some beginner question. I'm confused about how ```csharp builder.Services.AddDbContext<Onlinā” Difficulties with http requests for image(blob) column in mysqlSo i recently learned how to pull basic data from mysql but am struggling to find anything I think iCannot access file because it's being used by another processI am getting the following error when I try to run my program: `System.IO.IOException: 'The process print out all pairs of natural numbers whose sum isequal to the entered number nWrite an algorithm that prints out all pairs of natural numbers whose sum is equal to the entered nuā” "BLAZOR102: The scoped css file '~\Layout.cshtml.css' was defined but..." How do I fix this error?I've been messing around with ASP.NET and trying to make a new web app, originally I was having issu