I want to create a random number, store the digits of the random number into an array, then store the array into a string. I am trying to hide the digits from the user. This is what I have, it is only storing two numbers. How can i fix this or do it differently so it works?
int random,n,digit;
srand(time(NULL)); random = (rand() % 9999)+1000;
n= random;
char a[11];
int i = 0;
while (n > 0) {
long int digit = n % 10;
a[i] = digit;
++i;
n /= 10;
}
a[i] = '\0';
cout << digit << endl;
string hiddenNumber(to_string(digit).length(),'-');
'''
Aucun commentaire:
Enregistrer un commentaire