saladin pls help

By popular request a junk forum, to put worthless junk into.
Forum rules
Anymore harassment or abuse will be met with instant bans, that goes to both parties no matter who starts it.
Post Reply
User avatar
kob
CyberDemon
Posts: 12810
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

saladin pls help

Post by kob » Sat Feb 04, 2017 00:41

i don't know if you're familiar with C++ at all, but i'm doing an assignment for class and i'm completely lost why i'm getting an infinite loop. it's happening in the while loop in main() when I call the addTask function. when i tested the function multiple times prior to adding a loop (the loop is for a menu display) it was fine so i'm led to believe it's something to do with the while loop in main(), but i can't see what's wrong with it. the other options work fine as well - it's just that function when I call it. I've been doing this project for the past 6 or so hours and i'm just mentally beat and can't figure out what's wrong.

here's my code. the problem seems to be from line 33-60ish, particularly the first case in the switch statement.

https://gist.github.com/mkelley010/9013 ... 050de83638

User avatar
kob
CyberDemon
Posts: 12810
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

Re: saladin pls help

Post by kob » Sun Feb 05, 2017 02:02

i fixed it, it was a problem with the fact that i have cin taking input for the menu selection and then taking cin.get in my function right away. just had to clear the input buffer.

C++ is the worst

User avatar
Saladin
Spider Mastermind
Posts: 8410
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: saladin pls help

Post by Saladin » Sun Feb 05, 2017 02:12

Ayyyyyy. Nice job.

Still better than C, in some ways.

Get a good handle on this stuff if you can. Understanding low level fundamentals, pointers, memory, etc., is super helpful in the long term. The harder stuff is easier type grasp when you understand how it's broken down on the lower levels.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
Saladin
Spider Mastermind
Posts: 8410
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: saladin pls help

Post by Saladin » Sun Feb 05, 2017 02:14

Sorry, I didn't respond sooner. Didn't check the forums yesterday.

If you need immediate help in the future for an imminent assignment or something, hit me up on Facebook.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
kob
CyberDemon
Posts: 12810
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

Re: saladin pls help

Post by kob » Sun Feb 05, 2017 02:53

will do.

my only (real) experience with C is C-strings and i hate them. we have to use 'em for class (can't use string types at all) and it's such a chore. C++ is cool there's just so much shit it's nitpicky about.

yeah honestly the low level stuff is really difficult to grasp and it's the cause of a lot of my bugs, i think. like i couldn't tell you why not clearing the input buffer causes my program to go into an infinite loop, and the state of the input buffer isn't on my mind much, but from now on i'm going to be extra mindful of my cin statements. speaking of, how does cin.clear and cin.ignore work? like when do i use one or the other or both? using cin.ignore to ignore the newline character worked, but cin.clear does nothing.

User avatar
Saladin
Spider Mastermind
Posts: 8410
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: saladin pls help

Post by Saladin » Sun Feb 05, 2017 04:38

I forget the exactly why it's like that, but it's much better to know *why* than it is to know not to do that. I think failing to clear cin puts the OS into a state where it's constantly expecting new input. Manually clearing stuff like that is a staple of low level languages.

C++ is a mess of features. The guy who invented C++, Bjarme Stroustrup, famously said that on a scale of 1 to 10, he'd rate himself at about an 8 in terms of being an expert. You can even overload things like "New" for built in types and make them do completely different things. It's madness.

But understanding how things move from the compiler to the assembly to how it actually gets stored and computed helps a ton. Abstract data objects make way more sense that way.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
kob
CyberDemon
Posts: 12810
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

Re: saladin pls help

Post by kob » Sun Feb 05, 2017 04:54

that makes sense. i suppose that's why they're teaching us C++ since it seems to be pretty good for learning fundamentals.

that actually makes me curious what it'll be like programming in a higher level language. i don't have the perspective to know what the cons of C++ are - to me they're aspects that apply to every programming language. i know that's not true, but it's how it feels when you're starting to learn programming with C++.

User avatar
Saladin
Spider Mastermind
Posts: 8410
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: saladin pls help

Post by Saladin » Sun Feb 05, 2017 19:12

Yeah, all languages seem equally obtuse when you're starting out. Later on in your academic career, you'll start to think certain ones are "the best." Then, after that, you realize they're all basically just tools, and different tools work better in different circumstances.

Higher level languages are way easier, but they're very sloppy and inefficient. The highest level languages have crazy stuff like functional programming and functions that create functions for you, stuff that automates a ton of the work.

Higher level languages are theoretically always better if they reduce your workload. But you eventually reach a performance barrier and have to optimize somehow, which typically means doing more low level stuff.

Some companies are crazy about this. Insomniac, the studio behind Ratchet and Clank, are famous for programming entirely in C and C++, and then dropping down into their compiled assembly to do additional optimization if they feel it's too slow.

For the most part though, you just need to *know* this stuff. The practical concerns on a software team are rarely language or architecture based.
Quack wrote:ok but so now what do I do besides masturbate

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest