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
#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();
}

View File

@ -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() {

View File

@ -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<char>(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;
}
}
}

View File

@ -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<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
}
}