repl.it
@sdemodica/

Ch 7 Challenge Problem 15

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
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 <vector>
using namespace std;

//I got it to match the output in the book case study, thank you!

bool testPIN(vector<int>, vector<int>, int);

int main()
{
  int NUM_DIGITS = 7;
  
  vector<int> pin1 { 2, 4, 1, 8, 7, 9, 0 };
  vector<int> pin2 { 2, 4, 6, 8, 7, 9, 0 };
  vector<int> pin3 { 1, 2, 3, 4, 5, 6, 7 };

  if(testPIN(pin1, pin2, NUM_DIGITS))
    cout << "SUCCESS: pin1 and pin2 are different.\n";
  else
    cout << "ERROR: pin1 and pin2 report to be the same.\n";

  if(testPIN(pin1, pin3, NUM_DIGITS))
    cout << "ERROR: pin1 and pin3 report to be the same.\n";
  else
    cout << "SUCCESS: pin1 and pin3 are different.\n";

  if(testPIN(pin1, pin1, NUM_DIGITS))
    cout << "SUCCESS: pin1 and pin1 report to be the same.\n";
  else
    cout << "ERROR: pin1 and pin1 report to be different.\n";

  return 0;
}


bool testPIN(vector<int> custPIN, vector<int> databasePIN, int size)
{
  for(int index = 0; index < size; index++)
  {
    if(custPIN[index] != databasePIN[index])
      return false;
      break;
  }
  return true;
}
Fetching token
?