473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Having problem with illegal function definitions

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
5 3037
Banfa
9,065 Expert Mod 8TB
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
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
9,065 Expert Mod 8TB
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
johny10151981
1,059 1GB
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
@johny10151981
ok. thx for pointing that out. i'll try to make some modification about it
Jun 7 '10 #6

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

Similar topics

14
by: Joerg Schuster | last post by:
Hello, according to http://mail.python.org/pipermail/tutor/2001-July/007246.html the order of function definitions does matter in python. Does anyone know a trick to avoid this? Is there a...
2
by: Raymond Tinsel | last post by:
Hello all, I know this must be a newbie question, but I haven't found the solution in the tutorials I have read. For a dSPACE/Controldesk application I am defining several of my own modules....
5
by: Kobu | last post by:
Does anyone know how old style function definitions differ in "behaviour" to new style function definitions? I heard the old style function definitions caused integeral promotion and floating...
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
4
by: skinnybloke | last post by:
Hi - I am having problems witrh the code below (obviously) coming up with illegal character for various characters within the field name which is: S_Gift Finder1_0 I have tried various ways...
15
by: unknownbomb | last post by:
Hey all i really hope you can help me out. Im compiling a project and im getting 2 errors which are saying local function definitions are illegal. Anyone know what this mean? And especially...
1
by: kaygee | last post by:
Hi ppl can anyone tell me what this error means? error C2601: 'meanData' : local function definitions are illegal
1
by: nassegris | last post by:
Hello everyone! I'm trying to write a regular expression to capture VB6 function definitions and I'm abit stuck. The rules are: Function header: * Must contain the words SUB or FUNCTION *...
8
by: borophyll | last post by:
I don't understand the difference between these two declarations int foo(char a, char b) { ... } int foo(a, b) char a, b; {
3
by: MrHenry007 | last post by:
Hello! I'm fairly new to c++ but I have been following tutorials and have created functions before, but not one using a string. I can't work out what the problem is here. The function is supposed...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.