trying to get the pin number and asking for password

I need to compile a C++ program that simulates the authentication process. Store an actual PIN number in your program. The program should use an array to assign random numbers to the digits from 0 to 9. Display the random digits on the screen, input the answer from the user, and display whether or not the user's response correctly matches the PIN number.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  #include<iostream>
#include<cstdlib>
#include <time.h>
#include <string>
#include<cctype>
using namespace std;

int main()
 {
  int Actual_PIN[5]= {7,6,1,0,8};
  int Generated_Num[10];
  string Input;
  srand( (unsigned)time(NULL));
  for(int i=0; i<10; i++) {
    Generated_Num[i]= ( rand() % 3)+1;
  }
  cout <<" In order for you to log in, please enter "<<endl;
  cout <<"he corrosponding digits to your password as it's shown below"<< endl;
  cout <<" PIN : 0 1 2 3 4 5 6 7 8 9"<< endl;
  cout << " NUM : ";
  for (int i=0; i<10; i++)
    {
      cout << Generated_Num[i] << " ";
    }
  cout <<endl;
  cin >> Input;
  if ( Input.at(0) == Generated_Num[7] && Input.at(1) == Generated_Num[6] && Input.at(2) == Generated_Num[1] && Input.at(3) == Generated_Num[0] && Input.at(\
4) == Generated_Num[8])
    {
      cout << " your password is correct " <<endl;
    }
  else
    {
      cout << " your password is wrong " << endl;
    }
  return 0;
}

I keep getting the wrong password and I don't know what is wrong please help  
Your comparisons between the characters of Input and the elements of Generated_Num almost certainly will not work the way you think. Comparison with == will compare the ASCII code of the character with the number inside the integer array.

I'm not really sure what you are trying to do. Generate a random array then ask the user to repeat it back to you? If so, then why are you checking the characters of the input against (seemingly) arbitrary 'digits' in the generated number?
I just joined this forum to post this because your program prompt blew me away.

My roommate literally has the exact same question in his C++ class, he asked me to help him with it but I couldn't even wrap my head around what they were wanting him to do. Hopefully someone more insightful will help you out!
http://www.asciitable.com/

Visit this page. It is what Zhuge was telling you.

Character '0' = ASCII 48 (integer)
Character '1' = ASCII 49 (integer)
.....
etc...
Character '9' = ASCII 57 (integer)

You need to move the generated nums up to their respective ascii value if you're going to compare them with a char value

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

 #include<iostream>
#include<cstdlib>
#include <time.h>
#include <string>
#include<cctype>
using namespace std;

int main()
 {
  int Actual_PIN[5]= {7,6,1,0,8};
  int Generated_Num[10];
  string Input;
  srand( (unsigned)time(NULL));
  for(int i=0; i<10; i++) {
    Generated_Num[i]= ( rand() % 3)+1;
  }
  cout <<" In order for you to log in, please enter "<<endl;
  cout <<"he corrosponding digits to your password as it's shown below"<< endl;
  cout <<" PIN : 0 1 2 3 4 5 6 7 8 9"<< endl;
  cout << " NUM : ";
  for (int i=0; i<10; i++)
    {
      cout << Generated_Num[i] << " ";
    }
  cout <<endl;

  //Move up generated nums to their respective ASCII value
   for (int i=0;i<10; i++)
  {
	  Generated_Num[i]+=48;
  }
  
   cin >> Input;
  if ( Input.at(0) == Generated_Num[7] && Input.at(1) == Generated_Num[6] && Input.at(2) == Generated_Num[1] && Input.at(3) == Generated_Num[0] && Input.at(4) == Generated_Num[8])
    {
      cout << " your password is correct " <<endl;
    }
  else
    {
      cout << " your password is wrong " << endl;
    }
  system("pause");
  return 0;
}
Topic archived. No new replies allowed.