128: Write a program that input your ATM password from the user and check if entered password is valid or not. If password is valid, display the messege: "Welcome to the Bank". Otherwise program ask to re-enter password 3 times If user enters the correct password, say: "Welcome to the bank". Otherwise display the messege: "Sorry your card is Captured".

With while loop:

// Write a program that input your ATM password from the user and check
// if entered password is valid or not.
// If password is valid, display the messege: "Welcome to the Bank".
// Otherwise program ask to re-enter password 3 times
// If user enters the correct password, say: "Welcome to the bank".
// Otherwise display the messege: "Sorry your card is Captured".

#include <iostream>
using namespace std;
int main()
{
    int pin = 1234;
    int password;

    cout << "Enter your password: ";
    cin >> password;
    int i = 1;
    while (password != pin && i < 3)
    {

        cout << "Invalid Input\n";
        cout << "Re-enter your password: ";

        cin >> password;
        i++;
    }

    if (password == pin)
    {
        cout << "Welcome to the bank\n";
    }
    else if (password != pin)
    {
        cout << "Invalid Input\nSorry! Your card has been captured\n";
    }

    return 0;
}

With for loop:

// Write a program that input your ATM password from the user and check
// if entered password is valid or not.
// If password is valid, display the messege: "Welcome to the Bank".
// Otherwise program ask to re-enter password 3 times
// If user enters the correct password, say: "Welcome to the bank".
// Otherwise display the messege: "Sorry your card is Captured".

#include <iostream>
using namespace std;
int main()
{
    int pin = 1234;
    int password;

    cout << "Enter your password: ";
    cin >> password;

    for (int i = 1; password != pin && i < 3; i++)
    {

        cout << "Invalid Input\n";
        cout << "Re-enter your password: ";

        cin >> password;
    }

    if (password == pin)
    {
        cout << "Welcome to the bank\n";
    }
    else if (password != pin)
    {
        cout << "Invalid Input\nSorry! Your card has been captured\n";
    }

    return 0;
}

With do-while loop:

// Write a program that input your ATM password from the user and check
// if entered password is valid or not.
// If password is valid, display the messege: "Welcome to the Bank".
// Otherwise program ask to re-enter password 3 times
// If user enters the correct password, say: "Welcome to the bank".
// Otherwise display the messege: "Sorry your card is Captured".

#include <iostream>
using namespace std;
int main()
{
    int pin = 1234;
    int password;

    int i = 0;
    do
    {
        if (i == 0)
        {
            cout << "Enter your password: ";
        }
        else
        {
            cout << "Invalid Input\n";
            cout << "Re-enter your password: ";
        }

        cin >> password;
        i++;

    } while (password != pin && i < 3);

    if (password == pin)
    {
        cout << "Welcome to the bank\n";
    }
    else if (password != pin)
    {
        cout << "Invalid input\nSorry! Your card has been captured\n";
    }

    return 0;
}

Comments

Popular posts from this blog

153: Write a program to read an amount (integer value) and break the amount into smallest possible number of bank notes. Note: The possible banknotes are 500, 100, 50, 20, 10, 5, 2, and 1

206: Write a program to create a class named "Circle" which has the property "radius". Define functions to calculate the area and circumference of the circle.

221: // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent, and GraduateStudent classes in a university management system. Can you explain the advantages of using multilevel inheritance with specific details about the functions and data members in these classes? How were the parameterized constructors (e.g., setting student name, age, and ID) used to ensure that each class in the hierarchy correctly initializes its properties, such as creating an UndergraduateStudent named "John," aged 20, with a student ID of 12345