#### Pin Number Authenticator

Had a question on my code:

Write a program to simulate the authentication process. Store an actual 5-digit PIN number in your program (make one up, and store it as a constant). The program should use an array to assign random numbers to the digits from 0 to 9. Output the random digits to the screen, input the response from the user, and output whether or not the user’s response correctly matches the PIN number.

So this is what I have. I’ve literally stared at this for hours and can’t get my array to print out. I don’t know what I’m doing wrong here. Can anyone point me to where I have faltered?

``````#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

// Our Variables
int const PIN_NUMBER=12345;
int pin = PIN_NUMBER;
int coded_pin;
int num_array= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int rand_array;
int pin_array;
bool pin_match = true;

//Function Prototypes
void random_num(int num_array[]); // Function to give random mapping
void check_pin(int coded_pin, int pin, int rand_array[]); // Bool function to check the pin number
void printArray(int arr[], int arrSize); // Function to test our function

int main () {

cout<<"PIN: 0 1 2 3 4 5 6 7 8 9"<<endl;
cout<<"NUM: "; random_num(num_array);
cin>>coded_pin;

//Check if the entered pin matches
check_pin(coded_pin, pin, rand_array);

printArray(pin_array, 5);

return 0;
}

//Function Definitions
void random_num(int array[]) {
srand(time(NULL)); //set seed of random

//Generate random number array
for (int i = 0; i < 10; i++) {
rand_array[i] = rand() % 9;
}

//Print out the array to the console
for (int i = 0; i < 10 ; i++) {
cout<<rand_array[i]<<' ';
}
cout<<endl;
}

// Function Definition to check if the pin matches
void check_pin(int coded_pin, int pin, int rand_array[]) {

int div = 10000;
int curr_index = pin / div;

//Determine our resulting array, the pin array
for(int i = 0; i < 5 ; i++) {
pin_array[i]= rand_array[curr_index];
pin %= div;
div /= 10;
curr_index = pin / div;
}

div = 10000;

// Determine if the coded pin matches the pin_array
for(int i = 0; pin_match == true ; i++) {
if(pin_array[i] != coded_pin / div) {
pin_match = false;
}
else {
coded_pin %= div;
div %= 10;
}
}

//Our output to the console
if (pin_match == false) {
}
else {
}
}

// Function to test our Functions
void printArray(int arr[], int arrSize){
int i;

for (i = 0; i < arrSize ; i++) {
cout<<arr[i]<<' ';
}
cout<<endl;
}
``````

Source: Windows Questions C++