This is what i have so far. I'm not completely sure if this correctly assigns the random numbers to the array, so if it doesn't let me know. But I need a simple way to find the max value from the random generated numbers. Any help would be greatly appreciated.
You do not have an array in that code. You have a single varialbe 'num'. Every time you create a random number and assign it to num, you are erasing the old number.
If you want an array of 100 elements:
1 2 3 4 5
int num[100]; // make an array of 100 elements
for(...)
{
num[i] = ... // assigns the random number to a different element in the array each time
Here is a simple program I wrote when learning how to create and manipulate random numbers. This will generate a list of random numbers (1-100) then sequentially index them. I used the goto command which is usually frowned upon due to the creation of spaghetti logic, "unless it benefits the program" which in this case, I believe is true due to the fact that the logic is easy to follow. I also generated a couple cout statements so that one could see the stages of change the integers go through during process. Good Luck!
it works for me under 2 different compilers, watcom and visual studio express2008, let me check it out , ill get back to you, it should be something simple, isnt it always?? lol
ha, im using visual studio 2008. Idk why it isnt working, But i need it to assign the random numbers to the array, then i need to have a loop that finds the max value in the loop.
Error 1 error C2440: '=' : cannot convert from 'int' to 'int [30]' e:\assignment 4\assignment 4\assign4.cpp 18 Assignment 4
actually, i noticed that if i compile it with watcom, i have no trouble running it on watcom or visual studio, however, if i compile it with visual studio, it compiles, runs fine on watcom but i am noticing the same error message as you are getting using Visual Studio. So its a compiler issue, my first guess is that it has some sort of ambiguous interpetation of an otherwise correct code(that they warned us about in class!)I will go through the program and locate the problem using visual studio so that it can be addressed once and for all.
hey jdawg, ok, i changed the program a bit , one thing that was changed was instead of using two single dimension arrays i went with a two dimension array. I also eliminated the unnecesary cout statements. I compiled it with, and ran it through visual studio to insure it would work for you. I also tailored it to your specifications, it will now print out 30 random numbers ranging from 1-100. plus the final cout gives the location and value of the highest number of the 30 sampled. i dont think you will have any problems running this one. best of luck!!