diff --git a/libs/AtmAdmin.h b/libs/AtmAdmin.h index 64042d3..120d80f 100644 --- a/libs/AtmAdmin.h +++ b/libs/AtmAdmin.h @@ -3,11 +3,13 @@ #ifndef ATMADMIN_H #define ATMADMIN_H +#include "XMLStorage.h" + namespace AtmAdmin { // startup() is inline because of how small it is. char startup(); void handleInvalidArguments(int argc); - bool handleUserInformation(char choice, std::string& information); + bool handleUserInformation(char choice, XMLStorage& mainStorage); std::string changeAccountPin(); std::string changeAccountName(); } diff --git a/libs/XMLStorage.h b/libs/XMLStorage.h index ec0e46f..ccd91ce 100644 --- a/libs/XMLStorage.h +++ b/libs/XMLStorage.h @@ -16,6 +16,7 @@ namespace AtmAdmin { this->m_data ={initAccountNode(m_search)}; this->name ={m_data.child_value("name") }; + this->money ={std::stod(m_data.child_value("money"))}; this->pin ={std::stoi(m_data.child_value("pin")) }; } @@ -23,6 +24,7 @@ namespace AtmAdmin { pugi::xml_node initAccountNode (const std::string& toSearch); std::string name{}; + double money{}; int pin{}; // ~XMLStorage() { diff --git a/src/AtmAdmin.cpp b/src/AtmAdmin.cpp index b8b7a86..bcfef2e 100644 --- a/src/AtmAdmin.cpp +++ b/src/AtmAdmin.cpp @@ -5,6 +5,7 @@ #include "AtmAdmin.h" #include "Errorseal.h" +#include "XMLStorage.h" namespace AtmAdmin { // Used to make certain functions more concise and easier to read. @@ -31,7 +32,7 @@ namespace AtmAdmin { // Allows the user to double-check their inputted information. // It also saves and applies the information if the user accepts it. - void confirmUserInformation (std::string& information, const std::string& tempInformation, const Choice choice) { + void confirmUserInformation (XMLStorage& mainStorage, const std::string& tempInformation, const Choice choice) { char userCheck; bool loopDone = true; @@ -43,8 +44,8 @@ namespace AtmAdmin { std::cout << "Is this okay? (y or n) >: "; std::cin.get(userCheck); userCheck = static_cast(std::tolower(userCheck)); - if (userCheck == 'y') { - information = tempInformation; + if (userCheck == 'y' and choice == NAME) { + mainStorage.name = tempInformation; std::cout << "New name applied." << '\n'; loopDone = true; } @@ -63,7 +64,7 @@ namespace AtmAdmin { } // Controls the flow of the program based on the user's input. - bool handleUserInformation(char choice, std::string& information) { + bool handleUserInformation(char choice, XMLStorage& mainStorage) { std::string tempInformation{}; switch (choice) { @@ -75,7 +76,7 @@ namespace AtmAdmin { // This is handled by the if statement. tempInformation = changeAccountPin(); if (tempInformation != "invalid") { - confirmUserInformation(information, tempInformation, PIN); + confirmUserInformation(mainStorage, tempInformation, PIN); return true; } break; @@ -88,7 +89,7 @@ namespace AtmAdmin { tempInformation = changeAccountName(); if (tempInformation != "invalid") { - confirmUserInformation(information, tempInformation, NAME); + confirmUserInformation(mainStorage, tempInformation, NAME); return true; } break; @@ -97,7 +98,7 @@ namespace AtmAdmin { // The code below is a placeholder std::cout << "Enter the amount you wish to have: "; - std::cin >> information; + std::cin >> mainStorage.money; break; case 'q': return false; @@ -209,4 +210,4 @@ namespace AtmAdmin { std::ranges::transform (newName.cbegin(), newName.cend(), newName.begin(), [] (unsigned char input) { return tolower(input); }); return newName; } -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 108aa60..cd4fe4a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,12 +24,11 @@ int main(int argc, [[maybe_unused]] char** argv) { // The other functions should handle invalid choices. // ((1. Change pin || 2. Change money || 3. Change account name || Q. Exit the program)) char userChoice{startup()}; - std::string userInformation{}; // The bulk of the program, allowing user to interact with the program. // Always returns true unless 'Q' is entered. - continueLoop = AtmAdmin::handleUserInformation(static_cast(std::tolower(userChoice)), userInformation); + continueLoop = AtmAdmin::handleUserInformation(static_cast(std::tolower(userChoice)), mainStorage); - std::cout << userInformation << '\n'; // DEBUG + std::cout << "PIN: " << mainStorage.pin << " || NAME: " << mainStorage.name << " || MONEY: " << mainStorage.money << '\n'; // DEBUG } } \ No newline at end of file