aBefore you even read this, I'm gonna tell you that arrays are completely just confusing me to all extents. Well I need to make a 5 row 10 column array but I'm just competely perplexed. My class is just to big for my teacher to get to us all so if you guys would be so kind as to let me know what I'm doing wrong :)
- line 42 does nothing. What are you trying to do there?
- lines 43,44 declare 'row' and 'col' variables. You don't need to declare them again on lines 50,51.
- line 58 prints a single, non-existant, out of bounds element. Accessing alpha[5][10] is bad bad bad because the array is not that big. (you're trying to access the 6th row of an array that only has 5 rows)
- if you want to print the array, you have to loop through it and print each element individually.
- line 69 is all wrong. Since you are returning a comparison (<), it will return either 0 or 1 (false or true). Usually false.
- you're missing a closing brace to close the RandomNumber function
Line 42 I was simply trying to print the array. Deleted it.
lines 43/44 are because it says the variable wasn't be defined but that means I need to set it to 0 right? I run the program and I still get this error.
Line 58 - deleted. I get that now
I'm not sure how to print an array :/. I think that's one of my problems.
Line 48 is the error you are looking for i guess. alpha[5][10] = (rand(), rand());
This should be something like: alpha[row][col] = (rand(), rand());
Although you might want to use the % operator for getting only random integers smaller than 51 (Like rand()%51). Printing out an array is achieved by simply giving it to cout with a loop. It is like the initialization of the array only with cout .... << alpha[row][col] ... somewhere in it.
You might want to write the for loop like this
1 2 3 4 5 6
for(; row < NUMBER_OF_ROWS; row++)
for(; col < NUMBER_OF_COLUMNS; col++)
for(int row = 0; row < NUMBER_OF_ROWS; row++)
for(int col = 0; col < NUMBER_OF_COLUMNS; col++)
In the first case you will use the variables from lines 42,43. In the second case you delete lines 42,43. You can write it as you like, most people will use the second notation.
i fixed the alpha[5][10] problem thank you but I still get
Run Time Check Failure #3 - the variable "row" is being used without being initialized.
I get that error then
Run Time Check Failure #3 - the variable "col" is being used without being initialized.
How do I use the % operator? Can you give me an example?
Sorry i edit my post during you were writing. The edited post should be your solution.
An example is here: http://www.cplusplus.com/reference/clibrary/cstdlib/srand/ And in my post although. Simply use rand()%MAX_NUMBER+1 You might want to read about the modulo operator. It gives you the rest of a division. If you write i = 7%5 the value will be 2.
For you this means you will simply use (rand()%MAX_RANDOM_NUMBER)+1.
rand()%MAX_RANDOM_NUMBER generates values from 0-49 by adding one you get your desired random numbers
Thank you, I edited my post as well to give what my code looks like now but I can't experiment with my stuff because I get those run time error's mentioned above and I am perplexed at how to get rid of them.
I'm going to look at this rand() thing you mentioned while you get back to me. :)
You will have to initialize rand() normally you would initialize it using the actual time. So include #include <ctime> in your file and do only _once_ before using rand()
1 2
/* initialize random seed: */
srand ( time(NULL) );
This is although in the link above. The rest of your program you will have to figure out on your own. I guess it's not too difficult anymore. You will just have to adjust the ouput loop a little bit. There has to be inserted cout << endl; at some point.