>void main()
Incorrect, main returns int and nothing else.
>cout << "\n";
This shouldn't work because you included the new iostream header but you didn't specify that you are using cout.
>j++;
j hasn't been initialized, so it contains a garbage value at this point.
>getch();
Nonstandard, you can use cin.get() with the same results and your program will be more portable.
>srand(time(NULL));
This will have little effect because your loop will run so fast, all of the numbers will probably be the same. It would be much better to call srand once at the beginning of the program so that the seed is not reset with every iteration of the loop.
>number=rand() % 25;
Bzzzt! number is a pointer that doesn't point to anything, this will cause an access violation. This is also a poor way to use rand since the % operator works on the low order bits of the generator, and that usually results in not as random as you'd like numbers. A better way is to use the high order bits by dividing RAND_MAX by the number and then retrieving the random number in that range:
number = rand() / ( RAND_MAX / 25 )
>return number;
digit is typedef'd as an unsigned int yet you return an int, number is of the digit type so you would do better to return digit.
Code:
#include <iostream>
#include <cstring>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
typedef unsigned int digit;
digit randomize();
digit fill;
digit *number = &fill;
int main()
{
digit i, j = 0;
srand(time(NULL));
for (i=0;i<=6;i++) {
randomize();
}
cout << "\n";
while (j < 10) {
j++;
cout << j << ", ";
}
cin.get();
return 0;
}
digit randomize()
{
*number = rand() / ( RAND_MAX / 25 );
cout << *number << endl;
return *number;
}
-Prelude