Continued work on changeAccountName() & basic refactoring
This commit is contained in:
parent
36b46c6899
commit
dbe1063f29
|
@ -8,6 +8,7 @@ namespace AtmAdmin {
|
||||||
char startup();
|
char startup();
|
||||||
bool handleUserInformation(char choice, std::string& information);
|
bool handleUserInformation(char choice, std::string& information);
|
||||||
std::string changeAccountPin();
|
std::string changeAccountPin();
|
||||||
|
std::string changeAccountName();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //ATMADMIN_H
|
#endif //ATMADMIN_H
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include <iostream>
|
|
||||||
#include "Errorseal.h"
|
|
||||||
#include "AtmAdmin.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <oneapi/tbb/detail/_task.h>
|
#include <iostream>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
|
#include "AtmAdmin.h"
|
||||||
|
#include "Errorseal.h"
|
||||||
|
|
||||||
namespace AtmAdmin {
|
namespace AtmAdmin {
|
||||||
char startup() {
|
char startup() {
|
||||||
|
@ -36,8 +36,11 @@ namespace AtmAdmin {
|
||||||
// Ensure that the name is also converted to fully lowercase.
|
// Ensure that the name is also converted to fully lowercase.
|
||||||
|
|
||||||
// The code below is a placeholder
|
// The code below is a placeholder
|
||||||
std::cout << "Enter your new username: ";
|
tempInformation = changeAccountName();
|
||||||
std::cin >> information;
|
if (tempInformation != "invalid") {
|
||||||
|
information = tempInformation;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
// Simply a way to cheat, very straight-forward.
|
// Simply a way to cheat, very straight-forward.
|
||||||
|
@ -108,14 +111,25 @@ namespace AtmAdmin {
|
||||||
std::string changeAccountName() {
|
std::string changeAccountName() {
|
||||||
std::string newName{};
|
std::string newName{};
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Enter new name: ";
|
std::cout << "Enter new name: ";
|
||||||
std::cin >> newName;
|
std::cin >> newName;
|
||||||
Error::ignoreLine();
|
Error::ignoreLine();
|
||||||
|
|
||||||
if (newName.size() < 2 or newName.size() > 10) {
|
// Ensures the name is between 2 and 10 characters long.
|
||||||
|
if (newName.length() < 2 or newName.length() > 10) {
|
||||||
errorReport("Name has to be between 2 and 10 characters.");
|
errorReport("Name has to be between 2 and 10 characters.");
|
||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if the first character is a number.
|
||||||
|
if (isdigit(newName.at(0))) {
|
||||||
|
errorReport("First letter cannot be a digit.");
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turns all the letters into lowercase.
|
||||||
|
std::ranges::transform (newName.cbegin(), newName.cend(), newName.begin(), [] (unsigned char input) { return tolower(input); });
|
||||||
return newName;
|
return newName;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user