Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
What did it do?
I feel bad for you.
@RememberMe took my sanity away. Input validation is not working. Docs are unreadable and ununderstandable. All tutorials on "how to get int from cin" totally forget about entering not an int, forums are unhelpful with condescending computer veterans replying with unhelpful shit. I hate c++ with all my heart
@shoop I am a competitive coder and c++ is just the right thing. The template library makes your life hell lot easier.
If you finding it difficult, start with easy problems and syntax then move on.
@kehsihba well the problem was: get a number from the user, and output a string with correct grammar (Russian). It all worked fine until I started testing 3.5 where there was this weird type casting and it wouldn't compare anything properly and it was just a mess
Imo that's pretty beginner-level
@shoop When you encounter such problems, just refer to internet. There will be many people who must have got the same error when they have started.
Anyways, just changed the data type declaration to double.
@shoop are you casting to float and comparing?
Float comparisons are tricky.
And if you want input validation, read the input as a string, then check if it's valid, then convert it to int or whatever. An easy way to convert is to use atoi() once you've validated your string (check each char in the string via isdigit maybe).
The iDiOmAtIc C++ way to convert would be to use stringstream I guess but that's overkill for this.
@RememberMe I guess I could take in a string and convert it, but that's way more cumbersome than just doing a try catch when trying to do atoi, which doesn't work for some reason, or even better, just throw an exception when cannot put what's read into a variable. It's just so clunky
@shoop atoi is a C standard library function, it doesn't use exceptions because C doesn't have them. You can use setjmp+longjmp to implement an exceptions system in C if you want, but that's about it.
Look at the exceptions (C++) section.
Don't expect the C/C++ standard libraries to be like Python's or C#'s. There are a metric ton of legacy things, lots of stuff that were good ideas at the time but kinda pointless now, and lots of seriously good stuff (the STL for example). It's a lot more low level and manual than other languages, which is acceptable because of C/C++'s position in the industry.
These days you'd use C/C++ only if you want the low level, customisable, stable legacy language type codebase. I suggest you try Python or C# or Java instead if you want a cleaner, more modern and helpful API (though I'll still say that STL is amazing).
Skipp29What devrant taught me: Everyone hates java Everyone hates php Everyone hates spaces Everyone hates tabs Ever...
xjose97x14Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
Unskipp24So this happened last night... Gf: my favorite bra is not fitting me anymore Me: get a new one ? Gf: but it ...