So I'm making a seconds converter in C# for class. It's supposed to convert an integer entered into a textbox into appropriate units (seconds, minutes, hours, days) However, I can't for the life of me figure out what's causing these two errors.
>>52861475
1)You're writing outside the method
2)Your identation is fucked.
Just add 2 } after the red ~.
>>52861569
Scratch that first point, didn't quite see what the fuck was going on on the screen.
Fix your shit, man.
Also,
>login that close to UI
LOL
>>52861475
try } on line 33?
>>52861617
Fixed the previous issue, some new ones arise.
>>52861660
Delete the one 33, it should be 53
>>52861475
It's running now, somewhere I fucked up my math.
>>52861748
Try this number 4611686018427387903
>>52861977
Just shits itself.
>>52861999
I think I either fucked up lines 31-32 or lines 34, 39, 45 and 49
use floats you dummy
use longs you dummy
>>52862035
No its because the number you entered is larger than int32 can handle, don't worry about it.
use doubles you dummy
>>52862040
We haven't covered those. In week 5 of an intro course.
>>52862060
I... yes.
Yes of course.
>>52862060
dog you can't store decimal things like you're trying to do in lines 24-32 into an int
(ie 3601 / 60 = 60.01666...)
just change the int to double
>>52862060
>week 5
>code in op
bait confirmed. Congrats op, it was pretty convincing. But you won't fool me, I can see through your lies.
>>52862102
I agree. As much as I dont want to be a condescending asshole... Jesus Christ. Fix your indentation so you can at least see where one method begins and the other end.
OP your code is a horror show. Use floats or doubles. Also program may shit itself if you enter 3600.
>>52862094
Output needs to be whole numbers.
>>52862162
You can use MessageBox.Show(Math.Truncate(minutes.ToString() ... etc. I guess.
>>52862162
https://msdn.microsoft.com/en-us/library/system.math.round.aspx
>>52862156
It's obviously bait, vs even has a built in formatter, that instantly solves all these formatting issues.
Fuck you op
>>52862393
Nope, just inept, hoping not to be. Why I'm taking the course.
>>52862441
Damn, 5 weeks? If you only want to print integers, you should use Convert.ToInt32 or whatever on the output.
OP don't listen to these retards.
>>52862474
>>52862232
Read about the difference between decimal and float. Never use float for integral arithmetic.
>>52862560
He's not doing integral arithmetic. He needs to use float.
Often I love /g/ because I love technology but these threads make me realise what kind of morons browse /g/. And I'm not talking about OP. Looking at you here >>52862474 and >>52862232 and >>52862293 and >>52862160 and >>52862094 what the fuck >>52862057 >>52862050 >>52862040 what the fuckkkkkkkk
>>52862162
modulo doesn't work with floats you retard!
>>52862593
add this one >>52862590
>>52862629
Not using floats. Haven't even covered them.
>>52862642
>double
>>52862650
That's what I'm using.
Why the hell are people telling this dude to use floats?
Never uses floats for math that needs to be accurate, they're mainly use for graphics pipeline because they are fast and don't need to be spot on.
Use longs or doubles.
>>52862658
JUST
>>52862658
MODULO ONLY WORKS WITH INT!
>>52862662
>don't use floats, use doubles
AYY lmao
>>52862687
Doubles are twice as wide as floats, so you don't get the same rounding errors.
>>52862674
changed back to int
This whole thread is too good to be true.
>>52862715
ok i wrote this in C but i think it would be easy for you to convert this stuff?
int seconds,minutes,hours;
scanf("%d",&seconds);
minutes = seconds / 60;
hours = seconds / 3600;
printf("%d seconds,%d minutes,%d hours",seconds%60,minutes%60,hours%24);
Uhh guys, this code just looks disgusting and it was done by the worst way...
Think before you do something
Its not a hard mathematical challenge.
Right now, if I type in 3600, it displays the proper value in hours. If I type in 3601, it gives the same output. Also, if I type in 86400 (seconds in a day) It just gives the time in hours, same with any number above that.
>>52862968
neat
>>52862977
OP, there're already 2 solutions posted ITT just trash your code and learn something from people who know what they're doing
>>52862968
>>52862781
>>52861475
>.ToString() .ToString() .ToString() .ToString() .ToString()
jesus christ OP
https://msdn.microsoft.com/en-us/library/system.string.format%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
https://msdn.microsoft.com/en-us/library/dn961160.aspx
Guys, fuck this, i'm a c# student and i really suck at it but i'm giving this a try, see y'all in 40 with a solution
>>52861475
>C#
>C sharp
>sharp
>sarah sharp
>feminazi
>LGBT
bugger off OP...
done in about three minutesConsole.Write("Input time in seconds: ");
var input = Console.ReadLine();
uint totalSeconds;
if (!uint.TryParse(input, out totalSeconds))
{
Console.WriteLine("That is not a number!");
return;
}
var minutes = (totalSeconds / 60) % 60;
var hours = totalSeconds / 3600;
var secs = totalSeconds % 60;
Console.WriteLine("{0:00}:{1:00}:{2:00}", hours, minutes, secs);
Use Timespan::FromSeconds, then belonging properties that calculate this for you
>>52861475
Please don't ever get a programming job. Just go and flip burgers, it's probably all you're actually good at.
>>52863802
Thank you for the suggestion, I'll be sure to seriously consider it.
>>52863400
Done
>>52863852
that's disgusting
>>52863915
Thank you, but sadly i don't give a fuck because it works
>>52863934
>liking being a codemonkey and never improve
>>52863953
Chillout, i've never made any windows forms before, only asp.net with shitty template to finish.
You might want to know i just got into programming.
I know i'll get better than this.
>>52863852
Hey thanks a bunch, I modified it a bit to include days, works great.
>>52864013
You're welcome.
You could even add years, decennia, and millenia if you use the same sort of logic.
>>52864048
The possibilities are endless.
>>52863989
also
>using signed types for measuring time
worse than hitler
>>52864079
2^32
>>52864085
*2^31
this nigga is right >>52864081 i forgot to use unsigned.
>not using wpf
>not using the actual Converter class
>>52864121
It's homework and the teacher didn't tell us to use the OOP way
It's so fucking ugly.
>>52864149
Doesn't matter, it works.
Time to play Manhunt.
Night /g/, luv ya.
>>52864169
No you're writing C# of course it doesn't matter.
My point is that you're using the wrong language.
>>52864187
It's the required language for the intro course.
>>52863852
I converted time this way.
Is there anything here I shouldn't do?
Help me improve /g/.
>>52864376
instead of subtracting everything from seconds, just do int secs = seconds % 60;
>>52864376
move the rest of the code into try, so you don't execute it if exception occurs, or alternatively put return in the end of the catch block
>>52864452
So this then?
Any special reason for it? Or is it just considered more readable?
>>52864492
Ah yes, added a return, forgot to test that part.
Thanks.
>>52864519
You don't need to assing anything to seconds past the conversion. For the real seconds initialize another variable and set it to seconds % 60;
>>52861475
Holy fuck you're bad.
Please tell me you're not a student.
This is essential shit that you should be able to learn within 2 days.
holy fucking shit this thread's amazing
>>52864664
No, I'm actually not registered in the class, but I still get grades, had to pay for the text book. I'm so convincing that I actually have a student login.
>>52864539
I switched name to input rather than seconds to make it more clear.
Is this how you mean?
I was using seconds as both the input before and the seconds variable.
>>52864717
No, but it doesn't matter. Nothing matters.
>>52864704
Your coding is Rajeet-level, so, unless you literally live in India, you're never going to get a job.
With this disrespect for efficiency and form you're never going to get above code monkey level anyways.
Give it up, search for something else to do.
>>52864734
>>52864734
Okay, looking back I imagine you meant that I should do something similar to this >>52863591
Sorry for being retarded.
>>52864741
You must be having a bad day. Why not go for some ice-cream?
>>52864741
What the fuck did you just fucking say about me, you little bitch? I’ll have you know I declare all my variables at the top of my class in my IDEs, and I’ve been involved in numerous indie dev teams, and I have over 300 confirmed git pulls.
I am trained in office warfare and I’m the top developer in the entire cubicle farm. You are nothing to me but just another target. I will kill -9 you with precision the likes of which has never been seen before on this Earth, mark my fucking words.
You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of trolls across the darkweb and your IP is being traced right now so you better prepare for unsolicited dick pics, faggot. The storm that wipes out the pathetic little thing you call your social media account. You’re fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that's just with my guy fawkes mask.
Not only am I extensively trained in google-fu, but I have access to the entire backlog of Stack Overflow questions and I will use it to its full extent to wipe your miserable data off the face of the internet, you little shit. If only you could have known what unholy retribution your little “clever” comment was about to bring down upon you, maybe you would have held your fucking tongue.
But you couldn’t, you didn’t, and now you’re paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. I am legion. I do not forgive, I do not forget.
>>52864773
>Not only am I extensively trained in google-fu, but I have access to the entire backlog of Stack Overflow questions and I will use it to its full extent to wipe your miserable data off the face of the internet, you little shit.
>>52861475
>} expected
>>52864753
this
also, >>>/sci
>>52864773
>>52861475
ayy lmao mi familia, just use C, desu baka senpai familiadouble seconds,minutes,hours,days,weeks,years, months;
seconds = minutes = hours = days = weeks = years = months = 0.0F;
seconds = <secondsValue>;
if(seconds>60)
{
minutes = seconds/60;
seconds = (int)seconds%60;
if(minutes>60)
{
hours = minutes/60;
minutes = (int)minutes%60;
if(hours>24)
{
days = hours/24;
hours = (int)hours%24;
if(days>7)
{
weeks = days/7;
days = (int)days % 7;
if(weeks>4)
{
months = weeks/4;
weeks = (int)weeks % 4;
if(months>12)
{
years = months/12;
months = (int)months % 12;
}
}
}
}
}
}
puts("");
if(years)
{
printf("%d years\n",(int)years);
}
if(months)
{
printf("%d months\n",(int)months);
}
if(weeks)
{
printf("%d weeks\n",(int)weeks);
}
if(days)
{
printf("%d days\n",(int)days);
}
if(hours)
{
printf("%d hours\n",(int)hours);
}
if(minutes)
{
printf("%d minutes\n",(int)minutes);
}
if(seconds)
{
printf("%d seconds\n",(int)seconds);
}
>>52866047
>>52866175
>breaking kek
Kill self.
>>52866215
>do I fit in yet?
>>52866215
>not liking Breaking Bad
>>52866237
I do, you don't.
>>52866321
>liking subpar tv shows
I bet you like The Walking Kek and Game of Keks, too.
>>52866346
The Walking Dead was boring
Didn't watch Game of Thrones
>>52866323
What a tool
>>52866381
Good, that means you're not lost yet.
>>52866385
Yes, C is a good tool.
>>52862102
Judging from OP's abilities, they probably needed one week to install VS and another three to find the refactor.. which for some odd reason doesn't exist for VB.
>mfw half of this board doesnt even know how to write even c# correctly.
>This thread
>>52866531
dumb makiposter
>>52861475
Use format strings you stupid fuck.
>>52864376
>>52862968
>>52863852
>>52863591
>>52864717
>>52866047
Not using factory design pattern. -10/10 your chance of ever being ENTERPRISE EXPERT CODERS are negative.
>>52866600
>bloating up your code with OOP
baka
>>52866600
what a waste of dubs
poo in the loo, pajeet
>>52866600
What would your factory return?
>>52866705
instance of convertor
Now that is /g/-tier programming.
>>52866730
Is that a c# class? What can it do? I'm not familiar with the libs.
>>52866758
It's general OOP about "design patterns"
http://www.tutorialspoint.com/design_pattern/factory_pattern.htm
http://www.oodesign.com/factory-pattern.html
Pajeet is talking about Java which until 1980 + 34 didn't have function pointers / delegates. Everytime you needed a function pointer you had to implement a factory pattern.
http://stackoverflow.com/questions/1073358/function-pointers-in-java
>>52866730
This is how you ENTERPRISE CODE:
>factory that creates a time factory that creates a convertor factory
>>52866968
Yeah I know and I've used some before where applicable but.. a factory seems a bit strange in this case.
> the future "programmers" of crusty enterprise organizations try their hand at time conversions, C# edition
Freshmen are so cute.