By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,143 Members | 744 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,143 IT Pros & Developers. It's quick & easy.

Having problem with illegal function definitions

P: 3
i wrote some codes for my assignments.
then it came out several problems involving illegal local function definition.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void system_module();
  5. void card_module();
  6. int transaction_module();
  7. void traffic_control(int);
  8. void withdraw_module();
  9. void deposit_module();
  10. void transfer_module();
  11. void inquiry_module();
  12. void receipt_module();
  13. void repeat_module();
  14.  
  15. int saving = 10000;
  16. int current = 10000;
  17.  
  18. int main()
  19. {
  20.     int trans;                        /*trans stands for transaction type*/
  21.  
  22.     trans = transaction_module();
  23.     traffic_control(trans);
  24.     return 0;
  25. }
  26.  
  27. void system_module()
  28. {
  29.     char login;
  30.  
  31.     while (login != 'S' && login != 'X')
  32.     {
  33.         cout << "Please type S to start or X to Exit : ";
  34.         cin >> login;    
  35.     }
  36.  
  37.     if (login == 'S')
  38.     {    
  39.         cout<<"Welcome to Southern Bank SDN. BHD.  How may I help you today ?\n";
  40.     }
  41.     else if (login == 'X')
  42.     {
  43.         cout << "System is shutting down. \n";
  44.     }
  45. }
  46.  
  47. void card_module()
  48. {
  49.     char card; 
  50.     const int pw=920117;
  51.     int x = 3, pin;
  52. start:
  53.     while (card != 'I' && card != 'C')
  54.     {
  55.         cout << "Press I to insert card or C to cancel : ";
  56.         cin >> card;
  57.     }
  58.  
  59.     if (card == 'I')
  60.     {
  61.         cout << "Please insert PIN number : ";
  62.         cin >> pin;
  63.  
  64.         if (pin != pw && card != 'C')
  65.         {
  66.             while (x > 0 )
  67.             {
  68.                 cout << "Wrong PIN number entered. Please try again. " << "[" << x << " more chance(s)]\n\a";
  69.                 x = x - 1;
  70.                 cout << "Please reinsert PIN number : ";
  71.                 cin >> pin;
  72.             }
  73.  
  74.                 cout << "Your card has been barred from further use. Please ask the bank for assistance.\n";
  75.         }
  76.         else if (pin == pw)
  77.         {
  78.             cout << "PIN number aunthenticated. \n";
  79.         }
  80.     }
  81.     else if (card == 'C')
  82.     {
  83.         cout << "Session canceled. Please take your card. Have a nice day ! \n";
  84.         goto start; /*To be continued*/
  85.     }
  86. }
  87.  
  88. int transaction_module()
  89. {
  90.     int type;
  91.  
  92.     cout << "1. Cash Withdrawal \t\n";
  93.     cout << "2. Cash Deposit \t\n";
  94.     cout << "3. Money Transfer \t\n";
  95.     cout << "4. Balance Inquiry \t\n";
  96.     cout << "5. Abort \t\n";
  97.     cout << " Please select transaction : ";
  98.     cin >> type;
  99.  
  100.     return type;
  101. }
  102.  
  103. void traffic_control(int trans)
  104. {
  105.     switch (trans)
  106.     {
  107.     case 1:{goto withdraw;break;}
  108.     case 2:{goto deposits;break;}
  109.     case 3:{goto transfer;break;}
  110.     case 4:{goto inquiry;break;}
  111.     }
  112.  
  113.  
  114.         void withdraw_module();
  115.         {
  116.             int acc, draw;
  117.         withdraw:
  118.             while (acc != 1 && acc != 2 && acc != 3)
  119.             {    
  120.                 cout << "1. Saving Account \t\n";
  121.                 cout << "2. Current Account \t\n";
  122.                 cout << "3. Cancel \t\n";
  123.                 cout << "Select your account to withdraw money from : ";
  124.                 cin >> acc;
  125.             }
  126.  
  127.             {
  128.                 while (acc == 3)
  129.                 {
  130.                     cout << " Thank you for using our services. \n";break;            /*need some modification*/
  131.                 }
  132.  
  133.                 if (acc == 1)
  134.                 {
  135.                     while (saving >= 0)
  136.                     {
  137.         saving:
  138.                         cout << " Saving account currently has RM " << saving << endl;
  139.                         cout << " Enter the amount you want to withdraw : RM ";
  140.                         cin >> draw;
  141.  
  142.                         if ( saving >= draw)        
  143.                         {
  144.                             saving = saving - draw;break;
  145.                         }
  146.  
  147.                         else if (saving < draw)
  148.                         {
  149.                             cout << "Insufficient fund. Please reenter the amount. \n";
  150.                             goto saving;
  151.                         }
  152.                     }
  153.                 }    
  154.  
  155.                 else if (acc == 2)
  156.                 {
  157.                     while (current > 0)
  158.                     {
  159.         current:
  160.                         cout << "Current account currently has RN " << current << endl;
  161.                         cout << "Enter the amount you want to withdraw : RM";
  162.                         cin >> draw;
  163.  
  164.                         if ( current > draw)        
  165.                         {
  166.                             current = current - draw;break;
  167.                         }
  168.  
  169.                         else
  170.                         {
  171.                             cout << "Insufficient fund. Please reenter the amount. \n";
  172.                             goto current;
  173.                         }
  174.                     }
  175.                 }
  176.                 goto receipt;
  177.             }
  178.         }
  179.  
  180.         void deposit_module()
  181.         {
  182.             int acc, deposit;
  183.         deposits:
  184.             while (acc != 1 && acc != 2 && acc != 3)
  185.             {    
  186.                 cout << "1. Saving Account \t\n";
  187.                 cout << "2. Current Account \t\n";
  188.                 cout << "3. Cancel \t\n";
  189.                 cout << "Select your account to deposit money to : ";
  190.                 cin >> acc;
  191.             }
  192.  
  193.             {
  194.                 while (acc == 3)
  195.                 {
  196.                     cout << " Thank you for using our services. \n";break;            
  197.                 }
  198.  
  199.                 if ( acc == 1)
  200.                 {
  201.                     cout << " Saving account currently has RM " << saving << endl;
  202.                     cout << " Enter the amount you want to deposit : RM ";
  203.                     cin >> deposit;
  204.                     saving = saving + deposit;
  205.                 }    
  206.  
  207.                 else if (acc == 2)
  208.                 {
  209.                     cout << "Current account currently has RN " << current << endl;
  210.                     cout << "Enter the amount you want to deposit : RM";
  211.                     cin >> deposit;
  212.                     current = current + deposit;
  213.                 }
  214.                 goto receipt;
  215.             }
  216.         }
  217.  
  218.         void transfer_module()
  219.         {
  220.             int acc, acc2, amount;
  221.             acc = 0;
  222.             acc2 = 0;
  223.             amount = 0;
  224.         transfer:
  225.             {
  226.                 while (acc != 1 && acc != 2 && acc != 3)
  227.                 {    
  228.                     cout << "1. Saving Account \t\n";
  229.                     cout << "2. Current Account \t\n";
  230.                     cout << "3. Cancel \t\n";
  231.                     cout << "Select your account to transfer money from : ";
  232.                     cin >> acc;
  233.  
  234.                     switch (acc)
  235.                     {
  236.                     case 1 : {saving;break;}
  237.                     case 2 : {current;break;}
  238.                     case 3 : {cout << " Thank you for using our services. \n";break;}
  239.                     }
  240.  
  241.                         cout << "Enter the amount you want to transfer : RM";
  242.                         cin >> amount;
  243.                         acc = acc - amount;break;
  244.                 }
  245.  
  246.                 while (acc2 != 1 && acc2 != 2 && acc2 != 3)
  247.                 {
  248.                     cout << "1. Saving Account \t\n";
  249.                     cout << "2. Current Account \t\n";
  250.                     cout << "3. Cancel \t\n";
  251.                     cout << "Select your account to transfer money to : ";
  252.                     cin >> acc2;
  253.  
  254.                     switch (acc2)
  255.                     {
  256.                     case 1 : {saving;break;}
  257.                     case 2 : {current;break;}
  258.                     case 3 : {cout << " Thank you for using our services. \n";goto start;break;}
  259.                     }
  260.                     acc = acc2 + amount;break;
  261.                 }
  262.             }
  263.             goto receipt;
  264.         }
  265.  
  266.         void inquiry_module()
  267.         {
  268.             int acc, acc2, amount;
  269.             acc = 0;
  270.             acc2 = 0;
  271.             amount = 0;
  272.         inquiry:
  273.             {
  274.                 while (acc != 1 && acc != 2 && acc != 3)
  275.                 {    
  276.                     cout << "1. Saving Account \t\n";
  277.                     cout << "2. Current Account \t\n";
  278.                     cout << "3. Cancel \t\n";
  279.                     cout << "Select your account for inquiry : ";
  280.                     cin >> acc;
  281.  
  282.                     switch (acc)
  283.                     {
  284.                     case 1 : {saving;break;}
  285.                     case 2 : {current;break;}
  286.                     case 3 : {cout << " Thank you for using our services. \n";break;}
  287.                     }
  288.  
  289.                     if (acc == 1)
  290.                     {
  291.                         cout << "Current balance of this account : RM "<<saving<<endl;break;
  292.                     }
  293.  
  294.                     else if (acc == 2)
  295.                     {
  296.                         cout << "Current balance of this account : RM "<<current<<endl;break;
  297.                     }
  298.  
  299.                     else if (acc == 3)
  300.                     {
  301.                         cout << " Transaction canceled. Thank you for using us. \n";break;
  302.                         goto start;
  303.                     }
  304.                 }
  305.             }
  306.         }
  307. }
  308.  
  309. void receipt_module()
  310. {
  311.     char receipt;
  312.  
  313.     cout << " Do you want to print receipt ? Y or N : ";
  314.     cin >> receipt;
  315.  
  316.     if (receipt == 'Y')
  317.     {
  318.         cout << " Receipt printed. Please collect it. \n";
  319.     }
  320.  
  321.     else if (receipt == 'N')
  322.     {
  323.         cout << "Thank you. Come back soon. \n";
  324.     }
  325. }
  326.  
  327. void repeat_module()
  328. {
  329.     char con;
  330.  
  331.     cout << "Do you still want to continue your session ? Y or N : ";
  332.     cin >> con;
  333.  
  334.     if (con == 'Y')
  335.     {
  336.         goto start;        /
  337.     }
  338.  
  339.     else if (con == 'N')
  340.     {
  341.         cout << "Thank you for banking with us. \n";
  342.     }
  343. }
Jun 5 '10 #1
Share this Question
Share on Google+
5 Replies

Banfa
Expert Mod 5K+
P: 8,968
You can't define functions inside other functions, you have put several functions inside traffic_control which need to be moved.
Jun 5 '10 #2

P: 3
thx. I've tried out.
but ended up with even more errors.
stating undefined labels , like inquiry, deposit etc
mind explaining for me ?
i'm still new to all this
Jun 5 '10 #3

Banfa
Expert Mod 5K+
P: 8,968
To explain it I would need to see the code that is causing the errors and the errors (copy and pasted) as well.

Based on what you have written in post #3 I can say that you have an error in your code somewhere.

BTW did you remove the ; from the end of line 114?
Jun 5 '10 #4

100+
P: 1,059
A little observation about the code
in void withdraw_module() lots of goto statement present. which is real scary. This is always possible to write a code without using goto statement. remove all of your goto statements.
about
Expand|Select|Wrap|Line Numbers
  1. goto receipt;
  2.  
in your entire code there is no label name
receipt
fix them. i think there is more goto statement without label

Best Regards
Johny
Jun 7 '10 #5

P: 3
@johny10151981
ok. thx for pointing that out. i'll try to make some modification about it
Jun 7 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.