Thursday, December 15, 2011

C++ programming, debuging?

I have made the source as below, and if I compile it,


it keeps getting a compile time error that I can not find.


Thank you for your help.








#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using std::cout;


using std::endl;


using std::cin;





typedef struct account{


char acc_num[20];


char name[20];


char balance[20];


} ACCOUNT;





void make_f( ACCOUNT *array);


void deposit_f(ACCOUNT *array);


void withdraw_f(ACCOUNT *array);


void inquire_f(ACCOUNT *array);





enum { MAKE_ACCOUNT=1, DEPOSIT, WITHDRAW, INQUIRE } ;











int num=0; // NUMBER OF ACCOUNTS


const int MAX =100;








int main()


{


int select;


ACCOUNT array[MAX];





while(1)


{


cout%26lt;%26lt; "Select transaction: \n";


cout%26lt;%26lt;"MAKE_ACCOUNT \n DEPOSIT \n WITHDRAW \n INQUIRE \n";





cin%26gt;%26gt; select;





switch(select)


{


case(1): make_f(array);


break;


case(2):deposit_f(array);


break;


case(3):withdraw_f(array);


break;


case(4):inquire_f(array);


break;


default: cout%26lt;%26lt; "wrong input";


break;





}





return 0;


}








void make_f( ACCOUNT *array)


{


cout%26lt;%26lt; "Input an account number you want to make : ";


cin%26gt;%26gt; array[num]-%26gt;acc_num;


cout%26lt;%26lt; "Input name: ";


cin%26gt;%26gt; array[num]-%26gt;name;





num++;


}











void deposit_f(ACCOUNT *array)


{


int i;


char acc_number[20];


int deposit;





cout%26lt;%26lt; "Input account number";


cin%26gt;%26gt; acc_number;





for(i=0;i%26lt;num;i++)


{


if(strcmp(acc_number,array[i]-%26gt;acc_n鈥?br>

{


break;


}


}





cout%26lt;%26lt; "Input the ammount of money to deposit:";


cin%26gt;%26gt; deposit;


(array[i]-%26gt;balance)+=deposit;


cout%26lt;%26lt;"Current balance is "%26lt;%26lt; array[i]-%26gt;balance%26lt;%26lt;endl;





}








void withdraw_f(ACCOUNT *array)


{


int withdraw;


char acc_number[20];





cout%26lt;%26lt; "Input account number";


cin%26gt;%26gt; acc_number;





for(i=0;i%26lt;num;i++)


{


if(strcmp(acc_number,array[i]-%26gt;acc_n鈥?br>

{





break;


}


}





cout%26lt;%26lt; "Input withdraw ammount: ";


cin%26gt;%26gt; withdraw;





array[i]-%26gt;balance-=withdraw;


cout%26lt;%26lt;"Current balance is "%26lt;%26lt; array[i]-%26gt;balance%26lt;%26lt;endl;


}











void inquire_f(ACCOUNT *array)


{


for(int i=0;i%26lt;num;i++)


{


cout%26lt;%26lt; "name: "%26lt;%26lt; array[i]-%26gt;name %26lt;%26lt; endl;


cout%26lt;%26lt; "account number : "%26lt;%26lt; array[i]-%26gt;acc_num %26lt;%26lt; endl;


cout%26lt;%26lt; "balance: "%26lt;%26lt; array[i]-%26gt;balance %26lt;%26lt; endl;


}


}|||G'day mate,





You are missing the ending brace } for the main function.





return 0;


}


}





This is why the compiler thinks you have internal functions. They are in the main function. The "local function definitions are illegal" errors.





It will also get rid of the "unexpected end of file found" as you have enough end braces }





Hope that helps.|||The code seems fine. One way of catching the problem would using the "exception handling" technique in C++, with some (Exception - Try, Catch, Finally). That would help u to identify the run-time error. and to decide how to handle it..|||Code looks all right.


=


Which compiler are you using?


- Check warning %26amp; optimization settings.

No comments:

Post a Comment