Question: Create an ATM Pin checking program in C++. It should only allow the user to enter an incorrect Pin three times before locking the account.

Create an ATM Pin checking program in C++. It should only allow the user to enter an incorrect Pin three times before locking the account.

** This is the code that I have written. I think it is pretty solid, it did EVERYTHING perfectly when I just had it all in the "int main", but the chapter is about Functions, so he wanted functionality added to it. I created a function and called it correctly I believe, and it is working perfectly when you enter the WRONG pin three times. The only thing I need to fix here is that when you enter the right pin, like say on the first try, it says "Access Granted" but then asks you to enter the pin again. I need for it to end the program when you enter the correct pin on say the first or second time. Please HELP!! I tried to add a "break;" but it said I could only do that for loops, not "if statements". I tried to change the if to a "do-while" but maybe I don't understand them as well. I know that there is one small tweak I can make to fix it, I just don't know what it is! Here is the code:

#include // STD IO Stream Library, Keyboard and Terminal Window

using namespace std;

const int PIN = 2353; // Pin Number Declared as a Constant Integer

void check_pin(int);

int main()

{

system("Color 0A"); // Lime Green on Black Display

int pin; // User-Entered Pin Number

int i; // Indexing Variable Declared as an Integer

for (i = 1; i < 4; i++)

{

cout << "Please Enter Your Pin Number: "; // Prompt User to Enter Pin

cin >> pin; // User Enters Pin

cout << endl;

check_pin(pin);

}

if (i > 2)

{

system("Color 4F"); // White on Red Display

cout << "You Have Entered the Wrong Pin Three Times! Access Denied! \a" << endl << endl; // Deny Access to the User

}

system("pause");

return 0;

}

void check_pin(int pinNum)

{

int count;

if (pinNum == PIN)

{

system("Color 2F"); // White on Green Display

cout << "Access Granted! " << endl << endl; // Allow User Access Upon Correct Pin

}

else

cout << "You Have Entered an Incorrect Pin Number! " << endl << endl; // Notify User of Incorrect Pin

return;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!