this could be the array way:
Code:
#include <iostream.h>
#include <rand.h>
#include <ctime>
using namespace std;
int main()
{
srand(GetTickCount());
string posses[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",};
const int MAX_NUMBER = sizeof(posses) / sizeof(string);
for (int i = 0; i < 10; i++)
{
int p = static_cast <double> (rand()) / RAND_MAX * MAX_NUMBER +1;
cout << posses[p];
}
cout << endl;
return 0;
}
I tested both the programs and when I executed my program a lot of times in a short period a critical error appeared and the program closed! Why?