i wrote some codes for my assignments.
then it came out several problems involving illegal local function definition.
then it came out several problems involving illegal local function definition.
Code:
#include <iostream>
using namespace std;
void system_module();
void card_module();
int transaction_module();
void traffic_control(int);
void withdraw_module();
void deposit_module();
void transfer_module();
void inquiry_module();
void receipt_module();
void repeat_module();
int saving = 10000;
int current = 10000;
int main()
{
int trans; /*trans stands for transaction type*/
trans = transaction_module();
traffic_control(trans);
return 0;
}
void system_module()
{
char login;
while (login != 'S' && login != 'X')
{
cout << "Please type S to start or X to Exit : ";
cin >> login;
}
if (login == 'S')
{
cout<<"Welcome to Southern Bank SDN. BHD. How may I help you today ?\n";
}
else if (login == 'X')
{
cout << "System is shutting down. \n";
}
}
void card_module()
{
char card;
const int pw=920117;
int x = 3, pin;
start:
while (card != 'I' && card != 'C')
{
cout << "Press I to insert card or C to cancel : ";
cin >> card;
}
if (card == 'I')
{
cout << "Please insert PIN number : ";
cin >> pin;
if (pin != pw && card != 'C')
{
while (x > 0 )
{
cout << "Wrong PIN number entered. Please try again. " << "[" << x << " more chance(s)]\n\a";
x = x - 1;
cout << "Please reinsert PIN number : ";
cin >> pin;
}
cout << "Your card has been barred from further use. Please ask the bank for assistance.\n";
}
else if (pin == pw)
{
cout << "PIN number aunthenticated. \n";
}
}
else if (card == 'C')
{
cout << "Session canceled. Please take your card. Have a nice day ! \n";
goto start; /*To be continued*/
}
}
int transaction_module()
{
int type;
cout << "1. Cash Withdrawal \t\n";
cout << "2. Cash Deposit \t\n";
cout << "3. Money Transfer \t\n";
cout << "4. Balance Inquiry \t\n";
cout << "5. Abort \t\n";
cout << " Please select transaction : ";
cin >> type;
return type;
}
void traffic_control(int trans)
{
switch (trans)
{
case 1:{goto withdraw;break;}
case 2:{goto deposits;break;}
case 3:{goto transfer;break;}
case 4:{goto inquiry;break;}
}
void withdraw_module();
{
int acc, draw;
withdraw:
while (acc != 1 && acc != 2 && acc != 3)
{
cout << "1. Saving Account \t\n";
cout << "2. Current Account \t\n";
cout << "3. Cancel \t\n";
cout << "Select your account to withdraw money from : ";
cin >> acc;
}
{
while (acc == 3)
{
cout << " Thank you for using our services. \n";break; /*need some modification*/
}
if (acc == 1)
{
while (saving >= 0)
{
saving:
cout << " Saving account currently has RM " << saving << endl;
cout << " Enter the amount you want to withdraw : RM ";
cin >> draw;
if ( saving >= draw)
{
saving = saving - draw;break;
}
else if (saving < draw)
{
cout << "Insufficient fund. Please reenter the amount. \n";
goto saving;
}
}
}
else if (acc == 2)
{
while (current > 0)
{
current:
cout << "Current account currently has RN " << current << endl;
cout << "Enter the amount you want to withdraw : RM";
cin >> draw;
if ( current > draw)
{
current = current - draw;break;
}
else
{
cout << "Insufficient fund. Please reenter the amount. \n";
goto current;
}
}
}
goto receipt;
}
}
void deposit_module()
{
int acc, deposit;
deposits:
while (acc != 1 && acc != 2 && acc != 3)
{
cout << "1. Saving Account \t\n";
cout << "2. Current Account \t\n";
cout << "3. Cancel \t\n";
cout << "Select your account to deposit money to : ";
cin >> acc;
}
{
while (acc == 3)
{
cout << " Thank you for using our services. \n";break;
}
if ( acc == 1)
{
cout << " Saving account currently has RM " << saving << endl;
cout << " Enter the amount you want to deposit : RM ";
cin >> deposit;
saving = saving + deposit;
}
else if (acc == 2)
{
cout << "Current account currently has RN " << current << endl;
cout << "Enter the amount you want to deposit : RM";
cin >> deposit;
current = current + deposit;
}
goto receipt;
}
}
void transfer_module()
{
int acc, acc2, amount;
acc = 0;
acc2 = 0;
amount = 0;
transfer:
{
while (acc != 1 && acc != 2 && acc != 3)
{
cout << "1. Saving Account \t\n";
cout << "2. Current Account \t\n";
cout << "3. Cancel \t\n";
cout << "Select your account to transfer money from : ";
cin >> acc;
switch (acc)
{
case 1 : {saving;break;}
case 2 : {current;break;}
case 3 : {cout << " Thank you for using our services. \n";break;}
}
cout << "Enter the amount you want to transfer : RM";
cin >> amount;
acc = acc - amount;break;
}
while (acc2 != 1 && acc2 != 2 && acc2 != 3)
{
cout << "1. Saving Account \t\n";
cout << "2. Current Account \t\n";
cout << "3. Cancel \t\n";
cout << "Select your account to transfer money to : ";
cin >> acc2;
switch (acc2)
{
case 1 : {saving;break;}
case 2 : {current;break;}
case 3 : {cout << " Thank you for using our services. \n";goto start;break;}
}
acc = acc2 + amount;break;
}
}
goto receipt;
}
void inquiry_module()
{
int acc, acc2, amount;
acc = 0;
acc2 = 0;
amount = 0;
inquiry:
{
while (acc != 1 && acc != 2 && acc != 3)
{
cout << "1. Saving Account \t\n";
cout << "2. Current Account \t\n";
cout << "3. Cancel \t\n";
cout << "Select your account for inquiry : ";
cin >> acc;
switch (acc)
{
case 1 : {saving;break;}
case 2 : {current;break;}
case 3 : {cout << " Thank you for using our services. \n";break;}
}
if (acc == 1)
{
cout << "Current balance of this account : RM "<<saving<<endl;break;
}
else if (acc == 2)
{
cout << "Current balance of this account : RM "<<current<<endl;break;
}
else if (acc == 3)
{
cout << " Transaction canceled. Thank you for using us. \n";break;
goto start;
}
}
}
}
}
void receipt_module()
{
char receipt;
cout << " Do you want to print receipt ? Y or N : ";
cin >> receipt;
if (receipt == 'Y')
{
cout << " Receipt printed. Please collect it. \n";
}
else if (receipt == 'N')
{
cout << "Thank you. Come back soon. \n";
}
}
void repeat_module()
{
char con;
cout << "Do you still want to continue your session ? Y or N : ";
cin >> con;
if (con == 'Y')
{
goto start; /
}
else if (con == 'N')
{
cout << "Thank you for banking with us. \n";
}
}
Comment