*edit* I see the indentation is weird, hope you can make out what the code does.
I'm new at programming so I thought I'd pop by for some questions regarding an assignment at my uni.
Just began with c++, have some experience in ada and python. I'm supposed to create a 'golf score tab' using two-dimensional arrays. In essence, I have to create the array that represents 20 golf courses, and the score for each course. As stated, there are 20 courses and each course can have 1-8 scores. So basically, I create the arrays, fill the 20 'slots' with random integers with a range from 1-20. This is what I've got so far (pardon the code, there are things that might not make any sense but I've tried several different things that I've gathered from different sites in order to make it work.):
void displayArray(int golf_array)
for (int i = 0; i < 20; i++)
for (int j = 1; j < 9; j++)
cout << golf_array[i][j] << " ";
cout << endl;
int main ()
cin >> f;
I get no output when I run this. Might be because I don't fully understand how to call functions yet. So help regarding that is also greatly appreciated. Also, the int f; cin >> f; is just some foul fix in order to prevent my program to immediately shut down once it's done. Don't really know how to properly fix this yet either.
Help is greatly appreciated. Thank you in advance!
The problem is you are not calling your functions in main(); those lines you have there are just definitions. If you do a quick read on the functions bit on the tutorial here, you should get a good answer. If you still aren't sure, please post again.
In function main() these two lines simply declare the functions (that is, tell the compiler that the function exists). You need to actively call the functions.
Instead of having magic numbers such as 20 or 8 or 9 scattered throughout the code, it is far better to use defined constants. That way, if you need to change the value, it just needs to change in one place, rather than altering many lines throughout the program.
When passing a 2D array as a parameter to a function, all but the first dimension must be specified in the function definition. However the function call need only use the name of the function.