Progress, but pin (and maybe name) changing is broken

This commit is contained in:
theskywinds 2025-06-13 12:35:54 +02:00
parent ca041c45d0
commit 96cf979d3f
4 changed files with 16 additions and 12 deletions

View File

@ -3,11 +3,13 @@
#ifndef ATMADMIN_H #ifndef ATMADMIN_H
#define ATMADMIN_H #define ATMADMIN_H
#include "XMLStorage.h"
namespace AtmAdmin { namespace AtmAdmin {
// startup() is inline because of how small it is. // startup() is inline because of how small it is.
char startup(); char startup();
void handleInvalidArguments(int argc); void handleInvalidArguments(int argc);
bool handleUserInformation(char choice, std::string& information); bool handleUserInformation(char choice, XMLStorage& mainStorage);
std::string changeAccountPin(); std::string changeAccountPin();
std::string changeAccountName(); std::string changeAccountName();
} }

View File

@ -16,6 +16,7 @@ namespace AtmAdmin {
this->m_data ={initAccountNode(m_search)}; this->m_data ={initAccountNode(m_search)};
this->name ={m_data.child_value("name") }; 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")) }; this->pin ={std::stoi(m_data.child_value("pin")) };
} }
@ -23,6 +24,7 @@ namespace AtmAdmin {
pugi::xml_node initAccountNode (const std::string& toSearch); pugi::xml_node initAccountNode (const std::string& toSearch);
std::string name{}; std::string name{};
double money{};
int pin{}; int pin{};
// ~XMLStorage() { // ~XMLStorage() {

View File

@ -5,6 +5,7 @@
#include "AtmAdmin.h" #include "AtmAdmin.h"
#include "Errorseal.h" #include "Errorseal.h"
#include "XMLStorage.h"
namespace AtmAdmin { namespace AtmAdmin {
// Used to make certain functions more concise and easier to read. // 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. // Allows the user to double-check their inputted information.
// It also saves and applies the information if the user accepts it. // 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; char userCheck;
bool loopDone = true; bool loopDone = true;
@ -43,8 +44,8 @@ namespace AtmAdmin {
std::cout << "Is this okay? (y or n) >: "; std::cout << "Is this okay? (y or n) >: ";
std::cin.get(userCheck); std::cin.get(userCheck);
userCheck = static_cast<char>(std::tolower(userCheck)); userCheck = static_cast<char>(std::tolower(userCheck));
if (userCheck == 'y') { if (userCheck == 'y' and choice == NAME) {
information = tempInformation; mainStorage.name = tempInformation;
std::cout << "New name applied." << '\n'; std::cout << "New name applied." << '\n';
loopDone = true; loopDone = true;
} }
@ -63,7 +64,7 @@ namespace AtmAdmin {
} }
// Controls the flow of the program based on the user's input. // 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{}; std::string tempInformation{};
switch (choice) { switch (choice) {
@ -75,7 +76,7 @@ namespace AtmAdmin {
// This is handled by the if statement. // This is handled by the if statement.
tempInformation = changeAccountPin(); tempInformation = changeAccountPin();
if (tempInformation != "invalid") { if (tempInformation != "invalid") {
confirmUserInformation(information, tempInformation, PIN); confirmUserInformation(mainStorage, tempInformation, PIN);
return true; return true;
} }
break; break;
@ -88,7 +89,7 @@ namespace AtmAdmin {
tempInformation = changeAccountName(); tempInformation = changeAccountName();
if (tempInformation != "invalid") { if (tempInformation != "invalid") {
confirmUserInformation(information, tempInformation, NAME); confirmUserInformation(mainStorage, tempInformation, NAME);
return true; return true;
} }
break; break;
@ -97,7 +98,7 @@ namespace AtmAdmin {
// The code below is a placeholder // The code below is a placeholder
std::cout << "Enter the amount you wish to have: "; std::cout << "Enter the amount you wish to have: ";
std::cin >> information; std::cin >> mainStorage.money;
break; break;
case 'q': case 'q':
return false; return false;
@ -209,4 +210,4 @@ namespace AtmAdmin {
std::ranges::transform (newName.cbegin(), newName.cend(), newName.begin(), [] (unsigned char input) { return tolower(input); }); std::ranges::transform (newName.cbegin(), newName.cend(), newName.begin(), [] (unsigned char input) { return tolower(input); });
return newName; return newName;
} }
} }

View File

@ -24,12 +24,11 @@ int main(int argc, [[maybe_unused]] char** argv) {
// The other functions should handle invalid choices. // The other functions should handle invalid choices.
// ((1. Change pin || 2. Change money || 3. Change account name || Q. Exit the program)) // ((1. Change pin || 2. Change money || 3. Change account name || Q. Exit the program))
char userChoice{startup()}; char userChoice{startup()};
std::string userInformation{};
// The bulk of the program, allowing user to interact with the program. // The bulk of the program, allowing user to interact with the program.
// Always returns true unless 'Q' is entered. // Always returns true unless 'Q' is entered.
continueLoop = AtmAdmin::handleUserInformation(static_cast<char>(std::tolower(userChoice)), userInformation); continueLoop = AtmAdmin::handleUserInformation(static_cast<char>(std::tolower(userChoice)), mainStorage);
std::cout << userInformation << '\n'; // DEBUG std::cout << "PIN: " << mainStorage.pin << " || NAME: " << mainStorage.name << " || MONEY: " << mainStorage.money << '\n'; // DEBUG
} }
} }