Codes For Programming in C++ Part 2
Codes For Programming in C++ Part 2
Code 1:
Code 2:
Output:
Code 3:
balance = 0.0;
cout << "Account created successfully. Initial balance: $" << balance << endl;
}
if (amount > 0) {
balance += amount;
cout << "Deposit successful. New balance: $" << balance << endl;
} else {
cout << "Invalid deposit amount. Please enter a positive amount." << endl;
}
}
while (true) {
cout << "\nBank Account Management System\n";
cout << "1. Create Account\n";
cout << "2. Deposit Money\n";
cout << "3. Withdraw Money\n";
cout << "4. Check Balance\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
createAccount(name, accountID, balance);
break;
case 2:
if (balance > 0) {
depositMoney(balance);
} else {
cout << "Please create an account first." << endl;
}
break;
case 3:
if (balance > 0) {
withdrawMoney(balance);
} else {
cout << "Please create an account first." << endl;
}
break;
case 4:
if (balance > 0) {
checkBalance(balance);
} else {
cout << "Please create an account first." << endl;
exit(0);
default:
cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}
}
Code 4:
Output: