From 36b46c689976b3d44cd454dfe19dd0b820523d8d Mon Sep 17 00:00:00 2001 From: theskywinds Date: Mon, 2 Jun 2025 12:54:39 +0200 Subject: [PATCH] Begun work on changeAccountName() --- src/AtmAdmin.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/AtmAdmin.cpp b/src/AtmAdmin.cpp index 4ed66b1..2295e2e 100644 --- a/src/AtmAdmin.cpp +++ b/src/AtmAdmin.cpp @@ -6,7 +6,6 @@ #include namespace AtmAdmin { - char startup() { char choice{}; std::cout << "1. Change PIN\n" << "2. Change account name\n" << "3. Change money\n" << "Q. Exit the program\n\n"; @@ -23,11 +22,6 @@ namespace AtmAdmin { switch (choice) { case '1': - // Implement a proper function for entering a new pin. - // The function should have a somewhat complex algorithm that forces the pin to be secure and unique. - // It should also enforce 4 numbers. - - // The code below is a placeholder. tempInformation = changeAccountPin(); if (tempInformation != "invalid") { information = tempInformation; @@ -60,17 +54,16 @@ namespace AtmAdmin { return true; } + // Allows for the quick and clean creation of error reports. + void errorReport (std::string_view error) { + std::cout << error << '\n'; + std::cout << "Press enter to continue..."; + std::cin.get(); + }; + std::string changeAccountPin() { std::string newPin{}; - // Allows for the quick and clean creation of error reports. - auto errorReport = [] (std::string_view error) { - std::cout << error << '\n'; - std::cout << "Press enter to continue..."; - std::cin.get(); - return "invalid"; - }; - std::cout << "Enter new pin: "; std::cin >> newPin; Error::ignoreLine(); @@ -111,4 +104,18 @@ namespace AtmAdmin { return newPin; } + + std::string changeAccountName() { + std::string newName{}; + + std::cout << "Enter new name: "; + std::cin >> newName; + Error::ignoreLine(); + + if (newName.size() < 2 or newName.size() > 10) { + errorReport("Name has to be between 2 and 10 characters."); + return "invalid"; + } + return newName; + } }