code rewiev thread - /g/ (#106166577) [Archived: 263 hours ago]

Anonymous
8/6/2025, 10:09:59 PM No.106166577
aiwaifu
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;
}
Replies: >>106166792 >>106166849 >>106166928
Anonymous
8/6/2025, 10:13:58 PM No.106166617
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;
}
Anonymous
8/6/2025, 10:15:29 PM No.106166625
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;
}
Anonymous
8/6/2025, 10:16:34 PM No.106166631
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();
}
Anonymous
8/6/2025, 10:18:20 PM No.106166650
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;
Anonymous
8/6/2025, 10:19:21 PM No.106166661
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;
}
Anonymous
8/6/2025, 10:32:09 PM No.106166792
>>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
Replies: >>106166901
Anonymous
8/6/2025, 10:37:58 PM No.106166849
>>106166577 (OP)
just put the fries in the bag mane, it's over
Replies: >>106166876
Anonymous
8/6/2025, 10:39:54 PM No.106166876
>>106166849
>t. studied cs to get a job
>as opposed to learn cs to get the skills
you were never gonna make it
Anonymous
8/6/2025, 10:42:12 PM No.106166901
>>106166792
Ill look into it, dänks
Replies: >>106166911
Anonymous
8/6/2025, 10:43:32 PM No.106166911
>>106166901
bïts
Anonymous
8/6/2025, 10:44:43 PM No.106166928
>>106166577 (OP)
my project here:
https://github.com/orlfman/ytdlpfrontend
Replies: >>106167307
Anonymous
8/6/2025, 11:19:49 PM No.106167307
>>106166928
id gladly add my 2 cents but i write C
i dont have anything constructive to say so have a bump instead
Anonymous
8/6/2025, 11:33:09 PM No.106167443
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.