Timeline for Passing arrays into function in tideman
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 26, 2021 at 17:42 | comment | added | bobthebuilder | Alright, I think it's better to leave this on hold and come back to it at the end of the course, thank's for the help though! | |
Feb 26, 2021 at 17:03 | comment | added | Robert S. Pratt |
You would write code in your record_preferences just as you did here. The logic of your loop and your statements will need to change, though; you cannot force the logic you are using into the confines of how the problem specifications want you to solve it. For example, I was able to solve this with a nested for loop structure with a single line of code. I'm sorry, but I don't know what else to help you with. You are using arrays correctly in your main and unless you show me how you are writing the record_preferences function, I cannot tell you why it isn't working.
|
|
Feb 26, 2021 at 16:47 | comment | added | bobthebuilder | I've edited it - all the code was what was supposed to be written inside record_preferences, but I couldn't get around the pointer/array issue so I just plucked it all straight into main. | |
Feb 25, 2021 at 18:06 | comment | added | Robert S. Pratt |
It does pass an entire array, but you don't need to understand pointers. You just need to understand arrays. You also don't need to pass an index to the function, as this should be taken care of inside of the function itself--you should not be changing the function declarations. If you want to edit your question to add your code for your record_preferences function, I can try to help you more, but I assure you that you can complete this without any knowledge of pointers. Your code inside the function will index into the array just as if you were writing code in the main function.
|
|
Feb 25, 2021 at 17:33 | comment | added | bobthebuilder | But just examine the syntax for a second: to me, logically, record_preferences(ranks[]) means an entire array is being passed into a function - and for that to work I'd need to understand pointers, while for your indexing solution to work, the parameter would have to be record_preferences(int i , int ranks[i]), but I've tried that and it failed to compile. | |
Feb 25, 2021 at 11:25 | comment | added | Robert S. Pratt |
No, it doesn't. I never once mentioned pointers; nothing about what we are discussing here is talking about pointers. You will use an index to get values from the ranks array in the record_preferences function just as was needed to add the values in the vote function. Your questions where "what does ranks[] mean?" and "how am I supposed to code record_preferences(ranks[]) ?", which my answer has answered. :) This is doable without the use of pointers and you have all of the knowledge you need. Don't overthink it and treat it like any other array.
|
|
Feb 25, 2021 at 11:12 | comment | added | bobthebuilder | Thanks for the lengthy comment, but it doesn't adresss the main issue: this would imply that I have knowledge of pointers at week 3 - I do not. | |
Feb 24, 2021 at 20:47 | history | answered | Robert S. Pratt | CC BY-SA 4.0 |