this code is a disgrace

This commit is contained in:
Xory 2025-09-24 16:16:45 +03:00
parent b2e898eeed
commit a397347001
5 changed files with 72 additions and 4 deletions

View file

@ -2,6 +2,38 @@
#include <string>
#include <iostream>
void add_entry(std::vector<std::vector<std::string>>& database, std::string key, std::string value) {
database.push_back({key, value});
}
void remove_entry(std::vector<std::vector<std::string>>& database, std::string key) {
int index = 0;
for (std::vector<std::string>& entry : database) {
index++;
if (entry[0] == key) {
database.erase(database.begin() + index);
}
}
}
void prompt_user(std::vector<std::vector<std::string>>& database) {
std::string mode;
std::cin >> mode;
if (mode == "add") {
std::string key;
std::string value;
std::cin >> key;
std::cin >> value;
add_entry(database, key, value);
} else if (mode == "rem") {
std::string key;
std::cin >> key;
remove_entry(database, key);
} else {
prompt_user(database);
}
}
int main() {
std::vector<std::vector<std::string>> database;
@ -10,8 +42,11 @@ int main() {
{ "john", "unwanted_guest"},
{ "laith", "ducc" }
};
for (std::vector entry: database) {
std::cout << entry[0] << " | " << entry[1] << std::endl;
while (true) {
for (std::vector entry: database) {
std::cout << entry[0] << " | " << entry[1] << std::endl;
}
prompt_user(database);
}
}