محاكاة للماكينة atm بلغة سي بلس بلس .

#include
#include
#include
#include
#include
#include

using namespace std;
int cleanscreen()
{
cout << “do you want to clear the screen? (y/n)\n”;
string s;
cin >> s;
if (s == “y”)
{
cout << “goodbye\n”;
system(“cls”);
return 0;
}
return 1;
}
// Function to check the password
int checkpasse (int pin)
{
int userPin;
cout << “please enter your password to check your balance\n”;
cin >> userPin;
if (userPin != pin)
{
cout << “Wrong PIN. Try again.\n”;
return 0;
}
return 1;
}
int main()
{
int pin = 1234;
int userPin;
int balance = 1000;
vector transactions;
int tries = 3;

cout << "Welcome to the ATM\n";
while (tries > 0)
{
    cout << "Please Enter your pin:\n";
    cin >> userPin;

    if (userPin == pin)
    {
        while (true)
        {
            cout << "Please wait\n";
            std::this_thread::sleep_for(std::chrono::seconds(1));
            cout << "Welcome to your account\n";
            cout << "Please choose from the following options:\n";
            cout << "1. Check balance\n";
            cout << "2. Deposit\n";
            cout << "3. Withdraw\n";
            cout << "4. Change PIN\n";
            cout << "5. View transaction history\n";
            cout << "6. Exit\n";
            int choice;
            cin >> choice;
            switch (choice)
            {
            case 1:
                cleanscreen();
                checkpasse(pin);
                cout << "Please wait\n";
                std::this_thread::sleep_for(std::chrono::seconds(1));
                cout << "Your balance is: " << balance << endl;
                transactions.push_back("Checked balance: " + to_string(balance));
                int ask_user;
                cout << "Do you want to continue? (1/0)\n";
                cin >> ask_user;
                if (ask_user == 0)
                {
                    cout << "Goodbye\n";
                    return 0;
                }
                ;
            break;
            case 2:
                cleanscreen();
                checkpasse(pin);
                cout << "Enter the amount you want to deposit:\n";
                int deposit;
                cin >> deposit;
                balance += deposit;
                cout << "Please wait\n";
                std::this_thread::sleep_for(std::chrono::seconds(3));
                cout << "Your new balance is: " << balance << endl;
                transactions.push_back("Deposited: " + to_string(deposit));

                break;
            case 3:
                cleanscreen();  
                checkpasse(pin);
                cout << "Enter the amount you want to withdraw:\n";
                int withdraw;
                cin >> withdraw;
                if (withdraw > balance)
                {
                    cout << "Insufficient funds\n";
                }
                else
                {
                    cout << "Please wait\n";
                    std::this_thread::sleep_for(std::chrono::seconds(2));
                    balance -= withdraw;
                    cout << "Your new balance is: " << balance << endl;
                    transactions.push_back("Withdrew: " + to_string(withdraw));
                }
                break;
            case 4:
                cleanscreen();
                checkpasse(pin);
                int newPin, confirmPin;
                int oldPin;
                cout << "Please unter your old password : \n";
                cin >> oldPin;
                if (oldPin != pin)
                {
                    cout << "Wrong PIN. Try again.\n";
                    break;
                }
                cout << "Enter your new PIN:\n";
                cin >> newPin;
                cout << "Confirm your new PIN:\n";
                cin >> confirmPin;
                if (newPin == confirmPin)
                {
                    pin = newPin;
                    cout << "PIN changed successfully\n";
                    transactions.push_back("Changed PIN");
                }
                else
                {
                    cout << "PINs do not match. Try again.\n";
                }
                break;
            case 5:
                cleanscreen();
                checkpasse(pin);
                cout << "Transaction history:\n";
                for (const string &transaction : transactions)
                {
                    cout << transaction << endl;
                }
                break;
            case 6:
                cout << "Goodbye\n";
                return 0;
            default:
                cout << "Invalid choice. Try again.\n";
            }
        }
    }
    else
    {
        tries--;
        if (tries > 0)
        {
            cout << "Wrong PIN. You have " << tries << " attempts left.\n";
        }
        else
        {
            cout << "Card is locked!\n";
        }
    }
}

cout << "please press enter to exit\n";
cin.ignore();
cin.get();
string s;
cout << "do you want to clear the screen? (y/n)\n";
cin >> s;
if (s == "y")
{
    cout << "goodbye\n";
    system("cls");
    return 0;
}

}

إعجابَين (2)