Hello! The snippet of code below keeps crashing right after "person[j].relationship = true;" (the cin.get()'s were just for debug purposes), at least that's what it seems like. The rest of the code has worked perfectly. Does anyone have any ideas as to why it's crashing? Thank you for your help!
I'm using Code::Blocks and after the program crashes, it gives me:
"Process returned -10737418119 (0xC0000005)." Otherwise there isn't anything else it gives me.
There isn't really a reason for those lines. Just habit to combine ifs with elses.
Sorry for the double post. It seems like I've resolved the for loop crash (to be honest, I'm not entirely sure because of the following), but is the code snippet below not valid? How would I go about creating a condition for the if statement that would make it so that each element is taken into consideration?
It would just crash when the code was what it was in the original post. I've since used the built in debugger, which was not providing me with anything I could use. I've also moved some of the conditions out to try and compartmentalize things to see if that could help, but it hasn't. This is what it looks like now:
Everything compiles fine, it's just at runtime that it crashes and I've been able to narrow it down to the above portion. It's been stumping me all day, but I can't seem to get either the if statement to work as I want it to or the for statement to even work when the if kind of works. Other times it runs fine, but the results default to the else if statement.
Sorry, away from my computer now, but that snippet is within another for loop that just runs through each object associated with the struct in another file. It's initialized in main using a vector ("vector<People> person(num_people)"[num_people=100]). I can update this post with the rest of main tomorrow (or all of the files in a zip) if it'll help, but I know that the rest of it worked fine as this part I'm working on now came after the rest of it.
I'm sorry. It works, but it's not necessarily what I'm going for. The loop terminates once it hits num_people by changing person[j].relationship to true (which is what I want to happen). And as I thought, I was missing something obvious with the conditions in my if statement. As the program runs, it was assigning person[j].relationship to true without opening it up to later revision assuming other factors. Seeing the change you offered, though, helped it click in my head, so thank you very much! I feel silly :P
At any rate, the loop crashing is solved. I was attempting to read person[q] when 'q' was greater than num_people, which limited the size of person[]. The if statement needed other conditions (and more use of parentheses) to limit what got compared properly.