aiwaifu
md5: 4f4f4e5faf2f6deeebb26fcf63e795f8
🔍
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
int main() {
while (true) {
int d1;
std::cout << "acc1\tpress\t1" << "\n";
std::cout << "acc2\tpress\t2" << "\n";
std::cout << "acc3\tpress\t3" << "\n";
std::cout << "please choose a number: ";
std::cin >> d1;
switch (d1)
{
case 1: {
static double current_1 = 0;
std::ifstream input("acc1.txt");
if (input.is_open()) {
input >> current_1;
input.close();
}
int choise1;
std::cout << "you are currently in account nr1\n";
std::cout << "current balance\t" << current_1 << "\n";
std::cout << "to deposit\tpress\t1\n";
std::cout << "to withdraw\tpress\t2\n";
std::cout << "to transfer\tpress\t3\n";
std::cout << "choose: ";
std::cin >> choise1;
switch (choise1)
{
case 1: {
double amount1;
std::cout << "how much would you like to deposit\n";
std::cout << "amount: ";
std::cin >> amount1;
current_1 += amount1;
std::cout << "balance: " << current_1 << std::endl;
std::ofstream output("acc1.txt");
if (output.is_open()) {
output << current_1;
output.close();
}
break;
}
case 2: {
double withdraw;
std::cout << "how much would you like to withdraw\n";
std::cout << "amount: ";
std::cin >> withdraw;
current_1 -= withdraw;
std::cout << "balance: " << current_1 << std::endl;
std::ofstream output("acc1.txt");
if (output.is_open()) {
output << current_1;
output.close();
}
break;
}
case 3: {
int target;
std::cout << "make a transaction to acc nr2 or nr3: ";
std::cin >> target;
if (target != 2 && target != 3) break;
double amount;
std::cout << "amount: ";
std::cin >> amount;
current_1 -= amount;
std::string target_file = (target == 2) ? "acc2.txt" : "acc3.txt";
double target_balance = 0;
std::ifstream read_target(target_file);
if (read_target.is_open()) {
read_target >> target_balance;
read_target.close();
}
target_balance += amount;
std::ofstream write_target(target_file);
if (write_target.is_open()) {
write_target << target_balance;
write_target.close();
}
std::ofstream write_current("acc1.txt");
if (write_current.is_open()) {
write_current << current_1;
write_current.close();
}
std::cout << "you sent " << amount << " to account " << target << "\n";
break;
}
default:
break;
}
break;
}
case 2: {
static double current_2 = 0;
std::ifstream input("acc2.txt");
if (input.is_open()) {
input >> current_2;
input.close();
}
int choise1;
std::cout << "you are currently in account nr2\n";
std::cout << "current balance\t" << current_2 << "\n";
std::cout << "to deposit\tpress\t1\n";
std::cout << "to withdraw\tpress\t2\n";
std::cout << "to transfer\tpress\t3\n";
std::cout << "choose: ";
std::cin >> choise1;
switch (choise1)
{
case 1: {
double amount1;
std::cout << "how much would you like to deposit\n";
std::cout << "amount: ";
std::cin >> amount1;
current_2 += amount1;
std::cout << "balance: " << current_2 << std::endl;
std::ofstream output("acc2.txt");
if (output.is_open()) {
output << current_2;
output.close();
}
break;
}
case 2: {
double withdraw;
std::cout << "how much would you like to withdraw\n";
std::cout << "amount: ";
std::cin >> withdraw;
current_2 -= withdraw;
std::cout << "balance: " << current_2 << std::endl;
std::ofstream output("acc2.txt");
if (output.is_open()) {
output << current_2;
output.close();
}
break;
}
case 3: {
int target;
std::cout << "make a transaction to acc nr1 or nr3: ";
std::cin >> target;
if (target != 1 && target != 3) break;
double amount;
std::cout << "amount: ";
std::cin >> amount;
current_2 -= amount;
std::string target_file = (target == 1) ? "acc1.txt" : "acc3.txt";
double target_balance = 0;
std::ifstream read_target(target_file);
if (read_target.is_open()) {
read_target >> target_balance;
read_target.close();
}
target_balance += amount;
std::ofstream write_target(target_file);
if (write_target.is_open()) {
write_target << target_balance;
write_target.close();
}
std::ofstream write_current("acc2.txt");
if (write_current.is_open()) {
write_current << current_2;
write_current.close();
}
std::cout << "you sent " << amount << " to account " << target << "\n";
break;
}
default:
break;
}
break;
}
case 3: {
static double current_3 = 0;
std::ifstream input("acc3.txt");
if (input.is_open()) {
input >> current_3;
input.close();
}
int choise1;
std::cout << "you are currently in account nr3\n";
std::cout << "current balance\t" << current_3 << "\n";
std::cout << "to deposit\tpress\t1\n";
std::cout << "to withdraw\tpress\t2\n";
std::cout << "to transfer\tpress\t3\n";
std::cout << "choose: ";
std::cin >> choise1;
switch (choise1)
{
case 1: {
double amount3;
std::cout << "how much would you like to deposit\n";
std::cout << "amount: ";
std::cin >> amount3;
current_3 += amount3;
std::cout << "balance: " << current_3 << std::endl;
std::ofstream output("acc3.txt");
if (output.is_open()) {
output << current_3;
output.close();
}
break;
}
case 2: {
double withdraw;
std::cout << "how much would you like to withdraw\n";
std::cout << "amount: ";
std::cin >> withdraw;
current_3 -= withdraw;
std::cout << "balance: " << current_3 << std::endl;
std::ofstream output("acc3.txt");
if (output.is_open()) {
output << current_3;
output.close();
}
break;
}
case 3: {
int target;
std::cout << "make a transaction to acc nr1 or nr2: ";
std::cin >> target;
if (target != 1 && target != 2) break;
double amount;
std::cout << "amount: ";
std::cin >> amount;
current_3 -= amount;
std::string target_file = (target == 1) ? "acc1.txt" : "acc2.txt";
double target_balance = 0;
std::ifstream read_target(target_file);
if (read_target.is_open()) {
read_target >> target_balance;
read_target.close();
}
target_balance += amount;
std::ofstream write_target(target_file);
if (write_target.is_open()) {
write_target << target_balance;
write_target.close();
}
std::ofstream write_current("acc3.txt");
if (write_current.is_open()) {
write_current << current_3;
write_current.close();
}
std::cout << "you sent " << amount << " to account " << target << "\n";
break;
}
default:
break;
}
break;
}
default:
std::cout << "no account under this number\n";
break;
}
}
return 0;
}
>>106166577 (OP)use methods/functions
and compose the path for your account files so that you dont need to change your code if you add an account
>>106166577 (OP)just put the fries in the bag mane, it's over
>>106166849>t. studied cs to get a job>as opposed to learn cs to get the skillsyou were never gonna make it
>>106166577 (OP)my project here:
https://github.com/orlfman/ytdlpfrontend
>>106166928id gladly add my 2 cents but i write C
i dont have anything constructive to say so have a bump instead
1. Change variable names so they're meaningful, reorganize your code if necessary
2. Never put magic numbers or constants in your code
3. Having a file that contains just one number sounds stupid.
4. You should think about scaling this kind of system, suppose the bank requires a 4-digit code to login for example or a debit card number and a password.