• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

Need help with C++ programming....

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

ice91785

Senior member
Oct 22, 2006
651
0
0
Originally posted by: you2
I'm not sure we should be doing your homework for you.

I am not asking for anyone to do the homework.......just to help me out with a looping statement
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Originally posted by: ice91785
I am not asking for anyone to do the homework.......just to help me out with a looping statement

How's it going now? did you get it to work?

A nice way to test could literally create a file with a list of numbers (quite verbose) and loop your check (this would require a change to my code since it exits once it finds it). Then use redirection to input this file so it checks them automatically. This way you get the input you want and you don't have to sit there typing it in. Although, do note that this is really selective testing, as you're choosing the numbers where sometimes you try to choose based on boundaries and such (which you could literally go from 1 to MAX_INT as I believe you chose to use an integer rather than a long. Doing so would provide pretty much optimal coverage over what you're "allowed" to enter).
 

Madwand1

Diamond Member
Jan 23, 2006
3,309
0
76
Originally posted by: ice91785
I am not asking for anyone to do the homework.......just to help me out with a looping statement

Don't kid yourself. The people here pretty much did the homework for you. Copy & paste and maybe an edit or two, and it's done.

If you ignored their code and worked on polishing your own code, that's fine, but please don't kid yourself about how much help you've gotten here.

/em grumble Why, in my day, we'd have to write code on cards, in ink, and it would go to another city to be run, and it'd come back with compile time errors or whatever days later.

OK, so I'm old.. The real point is that working out the looping / etc., is as much a part of the homework exercise as anything else, and most of us did all of this without anywhere near the amount of assistance you've gotten here. Don't kid yourself.
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: ice91785
Originally posted by: you2
I'm not sure we should be doing your homework for you.

I am not asking for anyone to do the homework.......just to help me out with a looping statement

What help do you need beyond eakers' first reply?
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Originally posted by: Madwand1
Don't kid yourself. The people here pretty much did the homework for you. Copy & paste and maybe an edit or two, and it's done.

Nah, don't get him wrong.. he never asked anyone for code. I personally provided some because I wanted to write some code for once :(. I never have the motivation to do personal projects, but I don't mind (attempting to) helping people. Although my work in this thread (to me) seems less than stellar, I actually used to tutor computer science courses and did quite well at it. Tutoring intro was the best though... the purdy math girls had to take intro :laugh:.
 

Madwand1

Diamond Member
Jan 23, 2006
3,309
0
76
Originally posted by: Aikouka
Nah, don't get him wrong.. he never asked anyone for code. I personally provided some because I wanted to write some code for once :(. I never have the motivation to do personal projects, but I don't mind (attempting to) helping people. Although my work in this thread (to me) seems less than stellar, I actually used to tutor computer science courses and did quite well at it. Tutoring intro was the best though... the purdy math girls had to take intro :laugh:.

I've tutored too. It's really hard to be responsible in tutoring -- to give some proper direction and help so that the student learns and really does the work, instead of doing the work yourself for the student. It's much easier all around to take the second approach. And here, obviously, several people like showing off what they can do, making the avoidance of doing the work for him that much harder.
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Originally posted by: Madwand1
I've tutored too. It's really hard to be responsible in tutoring -- to give some proper direction and help so that the student learns and really does the work, instead of doing the work yourself for the student. It's much easier all around to take the second approach. And here, obviously, several people like showing off what they can do, making the avoidance of doing the work for him that much harder.

The worst part is when they don't want help, but they just want an answer. I mean... at some points, I tried to explain something to them... and literally get as plain as "Well, if you have something that's true, you may want to do this or else this should happen." You know, something along those lines :p. Half the time, they never got it either >_>.

I think the worst experience I ever had was when I literally sat there for a good 10-15 minutes looking over some code because the person finished the program, but it wasn't working correctly. I couldn't find anything, so I said to try debugging it using certain values or viewing "working/temp variables" along the way. From that, I literally got a comment like, "Wow, you're worthless."
 

Madwand1

Diamond Member
Jan 23, 2006
3,309
0
76
Originally posted by: Aikouka
I think the worst experience I ever had was when I literally sat there for a good 10-15 minutes looking over some code because the person finished the program, but it wasn't working correctly. I couldn't find anything, so I said to try debugging it using certain values or viewing "working/temp variables" along the way. From that, I literally got a comment like, "Wow, you're worthless."

It's the same underlying problem. Not only are they not taking responsibility for doing the work themselves, they're taking it out on you for not doing it for you. It's their bug, not yours. It's rude in the first place to say such a thing. Even if you happen to think it, most people would not say it. But it's really bad to insult someone when they're trying to help you.

On the plus side, I found that it's good to find the same problems that you dealt with yourself early on -- mind-boggling recursion for example -- and see how much easier it has become to you now; that you actually learned something.
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: Aikouka
Originally posted by: Madwand1
I've tutored too. It's really hard to be responsible in tutoring -- to give some proper direction and help so that the student learns and really does the work, instead of doing the work yourself for the student. It's much easier all around to take the second approach. And here, obviously, several people like showing off what they can do, making the avoidance of doing the work for him that much harder.

The worst part is when they don't want help, but they just want an answer. I mean... at some points, I tried to explain something to them... and literally get as plain as "Well, if you have something that's true, you may want to do this or else this should happen." You know, something along those lines :p. Half the time, they never got it either >_>.

I think the worst experience I ever had was when I literally sat there for a good 10-15 minutes looking over some code because the person finished the program, but it wasn't working correctly. I couldn't find anything, so I said to try debugging it using certain values or viewing "working/temp variables" along the way. From that, I literally got a comment like, "Wow, you're worthless."

What an ungrateful bastard. Sometimes the error in the code is not obvious, and the best way to find it is by doing exactly what you told him to do.
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Originally posted by: mugs
What an ungrateful bastard. Sometimes the error in the code is not obvious, and the best way to find it is by doing exactly what you told him to do.

There's always one rotten apple in the bunch ;). I think I got him back though during a programming competition. We usually had two teams and I was on one and he was on the other. Well, I'm usually pretty decent at these competitions, although for some reason, I lose my edge when it comes to solving problems decently. But I was able to easily jettison my team ahead of their team by a hefty margin time-wise and even clobbered them with the practice problem (that I don't think they even finished :p). So it was like a silent victory.

It's always weird to me how my team (during the 3 years I attended the competitions) was always the first to (successfully) finish the practice problem (usually by a good 5 minutes), but we never do the best at the normal part.

I remember one problem dealing with telling time by having an angle and knowing what time the clock was stuck on. I had it almost working but could never figure out why during the competition. On the ride home, I realized that I wasn't precise enough (I only had second-based precision where I needed around millisecond-based precision). Then there was the time my roommate misspelled "receiver" on the first problem and it took them TWO HOURS to say "output error." I still make fun of him for that one and he still tries to pass it off :p.

Oh and this one college (Bryn Mawr) always sent teams of some fine womens to the competition :Q. I think I said something along the lines of, "Damn, now I know where I wish I went to college", to my old roommate (the one who misspelled "receiver" :p).
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
That's not a hard equation... how could I not be able to write a comment that's understandable to any layperson? "Uses math to process 2 and then every odd number following." If you can't understand how that works with just that... I donno if you should be the one to maintain my code .

You could write a comment that's understandable -- but to verify the correctness of that code I would have to sit down and work it out by hand (or step through it with a debugger and/or add temporary variables/printouts). In isolation it's not so bad, and that example wasn't particularly heinous, but when you have things like that all over the place (especially if they're not commented thoroughly) it becomes a nightmare.

We have some people that used to work on the code I have to maintain who really liked ternary operators and frequently combined expressions by using pre/post-increments in the middle of complex math (which also tended to involve macros that were hard to understand and sometimes had boundary condition bugs). It's not fun to deal with.

Originally posted by: Aikouka
Originally posted by: Madwand1
I've tutored too. It's really hard to be responsible in tutoring -- to give some proper direction and help so that the student learns and really does the work, instead of doing the work yourself for the student. It's much easier all around to take the second approach. And here, obviously, several people like showing off what they can do, making the avoidance of doing the work for him that much harder.

The worst part is when they don't want help, but they just want an answer. I mean... at some points, I tried to explain something to them... and literally get as plain as "Well, if you have something that's true, you may want to do this or else this should happen." You know, something along those lines :p. Half the time, they never got it either >_>.

I think the worst experience I ever had was when I literally sat there for a good 10-15 minutes looking over some code because the person finished the program, but it wasn't working correctly. I couldn't find anything, so I said to try debugging it using certain values or viewing "working/temp variables" along the way. From that, I literally got a comment like, "Wow, you're worthless."

I feel your pain. :beer:

In our CS classes we were very up-front about the fact that TAs were limited in how much assistance they could give you, and were not supposed to be realtime debuggers. It tended to only be a problem in the intro class -- you'd have people who had never programmed before, and were often getting frustrated and asking for too much help. Sometimes they'd even 'shop' TAs (going back when someone else was having office hours) to see if they could get more help that way. We kept track of frequent visitors, though... :evil:
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Originally posted by: Matthias99
You could write a comment that's understandable -- but to verify the correctness of that code I would have to sit down and work it out by hand (or step through it with a debugger and/or add temporary variables/printouts). In isolation it's not so bad, and that example wasn't particularly heinous, but when you have things like that all over the place (especially if they're not commented thoroughly) it becomes a nightmare.

We have some people that used to work on the code I have to maintain who really liked ternary operators and frequently combined expressions by using pre/post-increments in the middle of complex math (which also tended to involve macros that were hard to understand and sometimes had boundary condition bugs). It's not fun to deal with.

Well, I verified that equation in about half a minute just throwing it in notepad and writing out the first couple values just to make sure my mind didn't muss something up (as seen here, it's certainly possible :p). The best thing to do is realize that once you hit 3, odd number mod 2 is always 1, and odd num + 1 + 1 (or + 2) is always an odd number, so therefore you can conclude that it will always return an odd number (and since it's always +2, it's always the next odd number). But I agree, that one was a bit simpler to look at and some can be a real monster and a half.

Oh I love ternary operators :evil:! I should tell you about the time me and my old roommate were competing to see who could write the shortest program and I had quite a disadvantage as I refused to use parts of the standard library (I instead wrote my own functions that were a bit more efficient as they did just what I wanted and weren't as generic), so my code had a bit of "functional overhead." So how did I solve such a thing? I turned all of my while loops into for loops ... replace most if statements with ternary operators and a bunch of other evil things :laugh:. I think it's safe to say that I turned in the previous longer version for credit.

Originally posted by: Matthias99
In our CS classes we were very up-front about the fact that TAs were limited in how much assistance they could give you, and were not supposed to be realtime debuggers. It tended to only be a problem in the intro class -- you'd have people who had never programmed before, and were often getting frustrated and asking for too much help. Sometimes they'd even 'shop' TAs (going back when someone else was having office hours) to see if they could get more help that way. We kept track of frequent visitors, though... :evil:

I usually found it progressing through as the people who "liked computers" and decided to become CS majors stayed in the program. Once they realized that they couldn't do it, things got a bit better with the constant question asking. Although them fine ladies could get my attention easily :eek:. I even had some personal one-on-one time with some of them if you know what I means... ermm.. one-on-one tutoring time I mean ;). Another "epidemic" we had were the people who always put something off who really couldn't afford to do that. I usually either coded it on the first day I got it or the morning it was due (gotta love the challenge), but there were people who came in with nothing for a huge project on the night before it was due... and they expected tons of help. I was most certainly not going to be staying late on a Tuesday night... that's 50 cent draft night!

I was probably their best shot at tutoring, so anyone with left over questions ended up asking the professor who I think was even more ruthless than I was at giving out help :p. Although I thought she was a good professor, she never stressed efficiency much. I even wrote up some big long letter addressing the situation and why some higher-level courses should really push for that.
 

ice91785

Senior member
Oct 22, 2006
651
0
0
Originally posted by: Aikouka
Originally posted by: ice91785
I am not asking for anyone to do the homework.......just to help me out with a looping statement

How's it going now? did you get it to work?

Yeah I got the loop to work out for me for the most part :) Now just have to tackle the rest of the program. Thanks for the assistance guys
 

Madwand1

Diamond Member
Jan 23, 2006
3,309
0
76
Matthias has been pretty patient on that point. I'll simplify it -- if you wrote something like that in a shop I was leading, I'd make you re-write it. It wouldn't pass say 9/10 code reviews, unless you happened to be in a shop where 9/10 people thought just like you did on that point, and the chances of that are slim. Of course it could pass in a shop that didn't do any code reviews, but part of the point here is the difference between one type of shop and the other.

This is FYI, not meant to be antagonistic or express a wish to get into a long online argument on it. "Agree to disagree" might be the best we'll come to here. I'm with Matthias firmly on the readability and easily verifiability points -- generally human / think time is much more valuable than code efficiency, or the worst evil -- code text efficiency.

I'd use this discussion itself as an example -- how much time has been spent on this useless discussion of that bit of code? Too much. It's not worth it.
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Originally posted by: Madwand1
Matthias has been pretty patient on that point. I'll simplify it -- if you wrote something like that in a shop I was leading, I'd make you re-write it. It wouldn't pass say 9/10 code reviews, unless you happened to be in a shop where 9/10 people thought just like you did on that point, and the chances of that are slim. Of course it could pass in a shop that didn't do any code reviews, but part of the point here is the difference between one type of shop and the other.

Glad I don't work for you then, and I doubt I'd have to rewrite it where I work. As for trying to classify my place of employment as crass... well, I prefer leaving my place of employment out of discussions for certain reasons.

Honestly, if you care this much about that... well, let's just say that I feel sorry for you that your mental aptitude isn't up to the caliber to comprehend that simplistic statement without having to mull over it :roll:. I could see if it was some huge statement full of tons of operators and operands, but it's NOT ROCKET SCIENCE! My god, are you stuck in the concept that for loops should only contain var++? I guess var += 2 is even a bit edgy at this point.