Is this a good sub for programming help?
19 16 Dec 2015 06:42 by u/im_the_dude_man
Hey everyone, I'm currently in school and taking a c++ class. I'm having a bit of trouble on one of my last projects and was hoping my fellow goats could lend a hand.
Just wanted to make sure that was acceptable here as the subs that are more geared for that haven't had activity in months. Please just let me know before I go spamming my noob code all over the place.
17 comments
2 u/im_the_dude_man [OP] 16 Dec 2015 07:51
@Mercuenomia
The commented out code is where I am having trouble, I commented it out just so I could move on testing my program.
//Function to check Social Security Number string ssidCheck(string) { string input, a, b, c, d, e, f, g, h, j; bool checkInput; int len, numA, numB, numC, numD, numE, numF, numG, numH, numJ;
}
4 u/Karys 16 Dec 2015 08:23
What you're looking for here is
if (i == 3 && input[i] != '-')
4 u/Karys 16 Dec 2015 08:28
Also, I don't believe there's any benefit to explicitly declaring 7 strings for the 7 digits, as you can do it all in one line as
numA = stoi(input[0])
or numA = stoi(input.at(0)) if you prefer, I'm fairly certain they're functionally equivalent
1 u/im_the_dude_man [OP] 16 Dec 2015 09:17
Hmm I did not think of that, thank you. I'll try that out.
edit: I'm getting an error when I try that.
0 u/Karys 16 Dec 2015 21:58
I think I found the issue. You want a standalone string with a single digit in each of those variables. And by explicitly moving each character into it's own string, it add's a null termination character and gives each digit it's own location in memory. stoi takes a const string location, and reads until a null terminator, so my optimization actually doesn't help you. There's probably a way to do this as a one-liner, but it's not necessary. Would just look more elegant imo...
4 u/im_the_dude_man [OP] 16 Dec 2015 08:34
Oh man......I think I just gave myself permanent brain damage from that facepalm.
Thank you.
2 u/Karys 16 Dec 2015 08:41
You are welcome, fellow goat.
1 u/seerick 16 Dec 2015 15:33
Lol I know that feeling. As someone who has worked in the field for a little while I can say one of the most common things to happen when troubleshooting is missing the obvious. The first thing I do when I become stumped on a issue is step away for a little while. Stretch the legs, get some coffee, etc. Then come back and try to take a fresh look at the problem. A lot of times this works. When it does not then comes plan b; i.e. ask for help, it's amazing what a fresh pair of eyes can see as you just learned. Best of luck with your class. A C++ course in a EE major is what got me to switch my focus to comp sci!
1 u/manapot 16 Dec 2015 07:35
I'd love to see code on this sub. Granted I'm a c# dev, so I may not be able to help with a specific c++ question :P
1 u/im_the_dude_man [OP] 16 Dec 2015 07:43
Heh, any help would be greatly appreciated. I'm down to like 2 projects due at the end of the week now.
1 u/xyzzy 16 Dec 2015 14:03
/v/ProgrammingHelp might be the sub you look for. But it is practically unused.
0 u/im_the_dude_man [OP] 16 Dec 2015 14:30
Yeah, that's why I asked here real quick. This is probably going to be the only time I do this here and if anything I'll try to drum up some activity over in /v/ProgrammingHelp. I just have some tight time constraints.
0 u/Specter6 16 Dec 2015 14:08
"Over the last weeks I've been seeing buzzfeed doing" Yup, that's it, I'm done.