Random Data

I am in grade 11 Computer Sciences and i am having trouble with my programs and my instructor doesn't really know how to fix this. Maybe someone could take a look.

The cout at the end is outputting the wrong numbers and i don't understand why.

http://dl.dropbox.com/u/23026515/RandomData/main.cpp
cout<<"Most Common: "<<numbers[href]<<" Amount: "<<highest<<endl;

1
2
3
4
5
6
    if(numbers[i]>highest)
    {
        cout<<highest<<" - "<<i<<endl;
        highest=numbers[i];
        href=i; // href is the value at which the highest number is at.
    }

You're outputting the same number twice. You want to output randomdata[href]. Also, get rid of void main(), as it's non standard, #include <cstdlib> for srand() and rand(), and be careful never to call srand() more than once per program execution.
Thanks alot for the help.

Makes sence now. But i don't know what to use instead of void main()

If i only call srand() once and keep assigning values to a 1000 value array wouldn't it always be the same value?

Last edited on
int main() is standard. It should return 0 upon successful execution.

srand() seeds the random number generator. For each different seed, you get a different random-like sequence. So you just call it once, and then call rand() as many times as you want to get random-like numbers.
I was never taught how to do int main() D:
I don't even know what it does. -_-
main has to return an int. It indicates whether the program terminated correctly (0) or not (some other value). void main() is illegal. Some compilers implement it as an extension, but it's still non standard C++.
Well thats dumb. Thats what i was taught to do. But anyway, thanks for all the help!
Topic archived. No new replies allowed.