Oh i see. hmmm look like mi really affi guh read da c++ how to program book deh sigh.. to many pages.
So i edited the program to still use the menu but not to ask the user to enter the opening balance
Code:
#include <iostream>
using namespace std;
/*
*
*/
int choice;
int choice2;
class Account {
private:
int balance;
public:
Account(){
this->balance = 0;
}
Account(int a);
int creditAccount(int);
int debitAccount(int);
void getBalance();
};
void menu();
void submenu();
int main(int argc, char** argv) {
int amount;
Account user1(1000);
Account user2(500);
do {
menu();
cout << "Choice: ";
cin >> choice;
switch (choice) {
case 1:
submenu();
cout << "Choice: ";
cin >> choice2;
switch (choice2){
case 1:
user1.getBalance();
break;
case 2:
user2.getBalance();
break;
case 9:
break;
}
break;
case 2:
submenu();
cout << "Choice: ";
cin >> choice2;
switch (choice2){
case 1:
cout << "Please Enter Lodgement amount: ";
cin >> amount;
user1.creditAccount(amount);
break;
case 2:
cout << "Please Enter Lodgement amount: ";
cin >> amount;
user2.creditAccount(amount);
break;
case 9:
break;
}
break;
case 3:
submenu();
cout << "Choice: ";
cin >> choice2;
switch (choice2){
case 1:
cout << "Please Enter Withdrawal amount: ";
cin >> amount;
user1.debitAccount(amount);
break;
case 2:
cout << "Please Enter Withdrawal amount: ";
cin >> amount;
user2.debitAccount(amount);
break;
case 9:
break;
}
break;
case 9:
cout << "Thanks for Processing! Have a good Day!" << endl;
break;
default:
cout << "Invalid Option Selected. Please Try again!" << endl;
break;
cout << "Choice: ";
cin >> choice;
}
}while (choice != 9);
return 0;
}
void menu(){
cout << "###############################################################" << endl <<
"## Account Transaction Menu ##" << endl <<
"## ##" << endl <<
"## ##" << endl <<
"## Please select the number for the option needed: ##" << endl <<
"## ##" << endl <<
// "## 1. Enter Account Opening Balance ##" << endl <<
"## 1. Check Account Balance ##" << endl <<
"## 2. Make Account Lodgement ##" << endl <<
"## 3. Make Withdrawal from Account ##" << endl <<
"## 9. Exit ##" << endl <<
"## ##" << endl <<
"###############################################################" << endl;
}
void submenu(){
cout << "###############################################################" << endl <<
"## Account Transaction Menu ##" << endl <<
"## ##" << endl <<
"## ##" << endl <<
"## Please select the number for the option needed: ##" << endl <<
"## ##" << endl <<
"## 1. User1 ##" << endl <<
"## 2. User2 ##" << endl <<
"## 9. Back to Main ##" << endl <<
"## ##" << endl <<
"###############################################################" << endl;
}
Account::Account(int a){
if (a >= 0){
this->balance = a;
}
else {
cout << "Invalid Amount Entered" << endl;
this->balance = 0;
}
}
int Account::creditAccount(int a){
this->balance += a;
}
int Account::debitAccount(int a){
if((this->balance - a) >= 0)
{
this->balance -= a;
}else{
cout << "Error: insufficient funds." << endl;;
}
}
void Account::getBalance(){
cout << "The current available balance is: " << this->balance << endl << endl;
cin.get();
}
To find what you seek in the road of life, the best proverb of all is that which says: "Leave no stone unturned." Edward Bulwer Lytton