Thread: 1 Error I Cant Figure Out!! Tried All I Could Think Of!!

  1. #1
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29

    1 Error I Cant Figure Out!! Tried All I Could Think Of!!

    so im doing an assignment for college to build a banking database, i havent completed all of the functions yet but i have 1 error left that wont let me compile it, the error is
    improper use of typedef 'CUSTOMER' in function search_database
    the defenition for this error is

    "Your source file used a typedef symbol where a variable should appear in an expression.
    Check for the declaration of the symbol and possible misspellings. " i have tried this and i cant figure out what it is....

    here is my code plz help!!!

    Code:
     #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #define MAX_PERSONS 10
    
    /* Assignment 3A (55 Marks Needed)
        Write a Program To Create A Banking Database */
       
    /* Declaration Of Structures */
    
    
    struct acc_type
    {
    char name[50];
    float balance;
    };
    struct acc_type account[20];
    int number;
    int current;
    
    typedef struct acc_type ACC_TYPE;
    
    
    struct date
    {
        int day;
        int month;
        int year;
    };
    
    
    typedef struct date DATE;
       
       
    struct personnel
    {
        int number;
        int overdraft;
        int balance;
        int phone_number;
        int age;
        char occupation[25];
        char surname[25];
        char first_name[10];
        char address [50];
        char gender;
        DATE dob;
    };
    typedef struct personnel CUSTOMER;
       
    
    /* Function Prototypes */
    
    void add_a_customer(CUSTOMER []);
    void delete_a_customer(CUSTOMER []);
    void edit_a_customer(CUSTOMER []);
    void add_money_to_account(CUSTOMER []);
    void withdraw_money_from_account(CUSTOMER []);
    void display_a_customer(CUSTOMER []);
    void display_customer_details(CUSTOMER *);
    void apply_for_overdraft(CUSTOMER []);
    void init_database(CUSTOMER []);
    int  search_database(CUSTOMER [], int);
    int  menu(void);
    
    /* Main Program Scope */
    
    void main()
    
    {
        CUSTOMER persons[MAX_PERSONS];
        int menu_choice;
       
        init_database(persons);
       
        do
        {
            menu_choice = menu();
            switch ( menu_choice )
            {
                case 1 : add_a_customer(persons);
                         break;
               
                case 2 : delete_a_customer(persons);
                         break;
               
                case 3 : edit_a_customer(persons);
                         break;
                   
                case 4 : add_money_to_account(persons);
                         break;
               
                case 5 : withdraw_money_from_account(persons);
                         break;
               
                case 6 : apply_for_overdraft(persons);
                         break;
               
                case 7 : display_customer_details(persons);
                         break;
            }
           
        }
        while ( menu_choice != 0);
        
    }
       
         /* Menu Display */
    
     
    
            /*------------------------------------------------------------------------------------/    
                    | Function: Display A Menu                                                                     |
                    |                                                                                                            |
                    | Purpose: Display A Menu For The Customer To Make A Choice              |
                    |                                                                                                            |
                    | Arguements: Calls A Function When Choice Is Made                             |
                    |--------------------------------------------------------------------------------------*/
       
       
    int menu(void)
    {
            int choice;
          
            /*Display the menu to the user*/
            printf("1.  Add an account.\n\n");
            printf("2.  Delete an account.\n\n");
            printf("3.  Edit an account.\n\n");
            printf("4.  Add money into an account\n\n");
            printf("5.  Withdraw money from an account\n\n");
            printf("6.  Apply for an overdraft\n\n");
            printf("7.  Display Customer Details\n\n");
            printf("8.  Search Database\n\n");
            printf("0.  End program.\n\n");
          
            do
            {
                scanf("%d",&choice);
                fflush(stdin);
            } while( choice < 0 || choice > 9 );
          
            return choice;
    }
       
            /* Case 1 */
       
            /*------------------------------------------------------------------------------------/
                    | Function: Add A Customer                                                                    |
                    |                                                                                                            |
                    | Purpose: Add A Customer To The Banking System                                 |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
       
        void add_a_customer(CUSTOMER person_array[])
        {
            int i=0;
           
            /*Search The Array For Empty Slot.
                        An Empty Slot = 0                        */
           
            while ( person_array[i]. number !=0 && i < MAX_PERSONS )
                if ( i > MAX_PERSONS)
                    printf(" Unfortunatly The Database Is Full!!\n");
                else                                                   /* Add To Database */
                {
                    printf("\n\n Customer Number (1 To 4 Digits, Except 0) : ");
                    do
                        scanf( "%3d",&person_array[i].number);
                    while (person_array[i].number<=0);
                       
                   
                    /*Customer Details Gender */
                    printf("\n Customer Gender : " );
                    scanf ("%7s",person_array[i].gender);
                   
                       
                    /*Customer Details Name */
                    printf("\n Customer Surname (Maximum 25 Characters) : " );
                    scanf ("%25s",person_array[i].surname);
                    printf("\n First Name (Maximum 10 Characters) : " );
                    scanf ("%25s",person_array[i].first_name);
                   
                    /*Customer Details Date Of Birth */
                   
                    printf("\nDate Of Birth\n" );
                    printf("    Day (1 Or 2 Digits) ; ");
                    scanf ("%2d",&person_array[i].dob.day);
                    printf("    Month (1 Or 2 Digits ; ");
                    scanf ("%2d",&person_array[i].dob.month);
                    printf("    Year (1 Or 2 Digits ; ");
                    scanf ("%2d",&person_array[i].dob.year);
                   
                    /*Customer Details Occupation */
                   
                    printf("\nJob:");
                    scanf("%20s",person_array[i].occupation);
                    fflush(stdin);
                   
                    /*Customer Details Address */
                    printf("address of customer (max 50 chars):\n");
                    scanf("%50", person_array[i].address);
                    fflush(stdin);
                       
                    /*Customer Details Phone Number */   
                    printf("Phone Number :  ");
                    printf("Phone (7 Or 10 Digits) ; ");
                    scanf ("%10s",&person_array[i].phone_number);
                    fflush(stdin);
                   
                }
               
            }
           
            /* Case 2 */
           
            /*------------------------------------------------------------------------------------/
                    | Function: Delete A Customer                                                                |
                    |                                                                                                            |
                    | Purpose:Delete A Customer From The Banking System                           |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
                   
            void delete_a_customer(CUSTOMER person_array[])
           
            {
                int CUSTOMER_number;
                int pos;
               
            /* A Customer Is Deemed Deleted By Placing A 0 In The Customer Number */
               
            /* First The Customer Number Has To Be Obtained */
            printf(" Please Enter Your Personal Number : ");
           
                           
            scanf("%10d",&CUSTOMER_number);
           
              
            pos = search_database(person_array,CUSTOMER_number);
          
            if(pos == MAX_PERSONS)                    /* Yes */         
                printf("This Customer is not in the database\n");
            else                                      /* No */         
            {
                printf("Customer Account number %10d is deleted.\n",CUSTOMER_number);
                person_array[pos].number == 0;
            }
        }
       
       
        /* Case 3 */
       
            /*------------------------------------------------------------------------------------/
                    | Function: Edit A Customer                                                                   |
                    |                                                                                                           |
                    | Purpose: Edit A Customer From The Banking System                            |
                    |                                                                                                           |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
        
            void edit_a_customer(CUSTOMER person_array[])
            {
               
            int account_number;
            int i;
            int pos;
                
            pos = search_database(person_array,account_number);    
       
            printf("Customer Account Number to edit: ");
            do
            scanf("%d",&account_number);
            while(account_number <=0 || account_number > MAX_PERSONS);
           
           
            if(pos==MAX_PERSONS)
            printf("This customer is not in the database\n");
            else
            {
                  /* Customer Name */
            printf("\n\nCustomer Surname (Up to 25 letters): ");
            scanf("%25s",person_array[pos].surname);
               
            printf("\nFirst Name (Up to 10 letters): ");
            scanf("%10s",person_array[pos].first_name);
               
                  /* Customer Date Of Birth */ 
            printf("\nDate of Birth\n");
            printf("\nDay (1-31): ");
            scanf("%d",&person_array[i].dob.day);
            printf("\nMonth (1-12): ");
               
            scanf("%2d",&person_array[i].dob.month);
            printf("\nYear (2 digits i.e. 1990 is 90): ");
            scanf("%2d",&person_array[i].dob.year);
               
            printf("\nOverdraft Taken (Yes or No): ");
               
            scanf("%3s",person_array[i].overdraft);
           
              
            printf("\nBalance: ");
            scanf("%d",&person_array[i].balance);
            printf("\n\n");
           
            }
       
        }
    
            /* Case 4 */
    
            /*------------------------------------------------------------------------------------/
                    | Function: Add Money To An Account                                                   |
                    |                                                                                                           |
                    | Purpose: Add Money To A Customers Account                                      |
                    |                                                                                                           |
                    |                                                                                                           |
                    |--------------------------------------------------------------------------------------*/
    
     
    
            void add_money_to_account(CUSTOMER [])
    
            {
               
            float add_sum;
            char dummy;
               
            printf("\nThe current balance for %s is %c%4.2f",account[current].name,156,
            account[current].balance);
               
            printf("\nHow much do you want to add to the account? %c",156);
            dummy=getch(); /* Clear Out Input Buffer */
               
            scanf("%f",&add_sum);
            if(add_sum < 0)
            {
            printf("\nNo negative sums allowed here");
            return;
            }
            account[current].balance += add_sum;
            printf("\nThe new balance is %c%4.2f",156,account[current].balance);
            return;
            }
    
    
            /* Case 5 */
    
            /*------------------------------------------------------------------------------------/
                    | Function: Withdraw Money From An Account                                      |
                    |                                                                                                           |
                    | Purpose: Withdraw Money From A Customers Account                         |
                    |                                                                                                           |
                    |                                                                                                            |
                    |--------------------------------------------------------------------------------------*/
    
                void withdraw_money_from_account(CUSTOMER[])
           
            {
               
            float take_sum;
            char dummy;
               
            printf("\nThe current balance for %s is %c%4.2f",account[current].name,156,
            account[current].balance);
               
            if(account[current].balance == 0)
            {
               
            printf("\nThis account has zero balance - no overdraft facility!");
            return;
               
            }
           
            printf("\nHow much do you want to take from the account? %c",156);
            dummy=getch();//clear out input buffer
            scanf("%f",&take_sum);
           
            if(take_sum < 0)
            {
               
            printf("\nNo negative sums allowed here");
            return;
               
            }
           
            if(take_sum > account[current].balance)
               
            {
               
            printf("\nInsufficient funds!");
            return;
               
            }
           
            account[current].balance -= take_sum;
            printf("\nThe new balance is %c%4.2f",156,account[current].balance);
           
            }
           
                   
                   
    
     
    
            /* Case 7 */
       
            /*------------------------------------------------------------------------------------/    
                    | Function: Search Database                                                                  |
                    |                                                                                                            |
                    | Purpose: Search Database For Customer                                               |
                    |                                                                                                            |
                    |                                                                                                            |
                    |--------------------------------------------------------------------------------------*/
            
            int search_database(CUSTOMER [], int account_number)
            {
               
            int i =0;
    
            while (i<MAX_PERSONS && CUSTOMER[i].number != account_number)
            {
            i++;
            }
            return (i);
           
            }
       
    
            /* Case 8 */
       
            /*------------------------------------------------------------------------------------/
                    | Function: Display A Customer                                                               |
                    |                                                                                                            |
                    | Purpose: Display A Customer From The Banking System                         |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
       
        void display_a_customer( CUSTOMER person_array[] )
        {
            int CUSTOMER_number;
            int pos;
       
            /* Get The Customer Number */
            printf(" Customer Number To Display ( 1-4 Digits, Except 0) :");
            do
                scanf("%3d",&CUSTOMER_number);
                while( CUSTOMER_number <= 0);
                   
                /* Find The Customer In The Database */
                pos = search_database( person_array,CUSTOMER_number);
               
                /* Does The Customer Exist In The Databse */
                if ( pos == MAX_PERSONS) /* No */
                printf(" The Selected Customer Is Not In The Databse\n" );
                else                     /* Yes - Display The Details */
                    display_customer_details(&person_array[pos]);
            }
           
            /*------------------------------------------------------------------------------------/
                    | Function: Display A Customers Details                                                  |
                    |                                                                                                            |
                    | Purpose: Display A Customers Details From The Banking System            |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customers Details                                  |
                    |--------------------------------------------------------------------------------------*/
           
            void display_customer_details(CUSTOMER *ptr)
        {
            printf("\n\n");
            printf("Account number : %d\n",ptr->number);
            printf("Surname        : %s\n",ptr->surname);
            printf("Firstname      : %s\n",ptr->first_name);
            printf("Job            : %s\n",ptr->occupation);
            printf("Surname        : %s\n",ptr->surname);
            printf("Telephone      : %d\n",ptr->phone_number);
            printf("Date of Birth  : %2d/%2d/%2d\n",ptr->dob.day, ptr->dob.month, ptr->dob.year);
            printf("address        : %s\n",ptr->address);
        };

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Haven't spotted your problem yet but there are a few more problems with your code you should fix right away:

    1) void main should be int main(void) and should return 0 on successful completion.

    2) NEVER fflush(stdin), the behaviour of that is undefined.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    ok thanks ill hafte change them, thanks for the heads up!! its a tough assignment for a first year isnt it!! ha is that okay so far???

    Code:
    /* Main Program Scope */
    
    int main (void)
    
    {
        CUSTOMER persons[MAX_PERSONS];
        int menu_choice;
       
        init_database(persons);
       
        do
        {
            menu_choice = menu();
            switch ( menu_choice )
            {
                case 1 : add_a_customer(persons);
                         break;
               
                case 2 : delete_a_customer(persons);
                         break;
               
                case 3 : edit_a_customer(persons);
                         break;
                   
                case 4 : add_money_to_account(persons);
                         break;
               
                case 5 : withdraw_money_from_account(persons);
                         break;
               
                case 6 : apply_for_overdraft(persons);
                         break;
               
                case 7 : display_customer_details(persons);
                         break;
            }
           
        }
        while ( menu_choice != 0);
        return 0;
    }

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Ok the problem is that in your implementation of search_database you have no variable name for the CUSTOMER parameter. You must have copied and pasted it from the function declaration before main and forgot to add that.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    thanks man i just fixed it and that was the problem!! thanks alot!!

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You are welcome.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    ok i finally got the program to compile and run, now when i add the customer and fill in all the details it doesnt end the add loop it stays in it and just restarts again... do i jus add in another function to stop this and bring it back to the main menu??

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Ok a few things about that function:

    1) Your if condition inside the first while will never be true because i cannot be more than MAX in the loop, otherwise the loop would exit.

    If you turn your warning levels to highest the compiler should probably complain about that being an unreachable segment of code.

    2) You never increase i in that loop so it stays inside the do while block reading the person number for i = 0 indefinitely. Not sure what you wanted to do there exactly.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  9. #9
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    ok thanks, im getting abit confused at the moment i need it to increment but i dont no if i am putting it in the right place, when i put it in at the very end between the curly braces (because we want all the details first before it incriments) nothing happens :S

  10. #10
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    okay i managed to get the increment now i have a problem that when its taking in the customer details it goes down as far as address and displays the phone number prompt but skips it and goes back to the menu, i dno why cos i didn change anything, it was working fine

  11. #11
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Can you post your latest code?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  12. #12
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    i simply jus took out phone number becaua baggage and was not needed, now what i have come accross is that when i add a customer, it adds the first person, then i go to add the second person and when i display the details it says that the second person does not exist but that the first person does :S here is the code
    Code:
     #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #define MAX_PERSONS 10
    
    /* Assignment 3A (55 Marks Needed)
        Write a Program To Create A Banking Database */
       
    /* Declaration Of Structures */
    
    
    struct acc_type
    {
    char name[50];
    float balance;
    };
    struct acc_type account[20];
    int number;
    int current;
    
    typedef struct acc_type ACC_TYPE;
    
    
    struct date
    {
        int day;
        int month;
        int year;
    };
    
    
    typedef struct date DATE;
       
       
    struct personnel
    {
        int number;
        int overdraft;
        int balance;
        int age;
        char occupation[25];
        char surname[25];
        char first_name[10];
        char address [50];
        char gender[];
        DATE dob;
    };
    typedef struct personnel CUSTOMER;
       
    
    /* Function Prototypes */
    
    void add_a_customer(CUSTOMER []);
    void delete_a_customer(CUSTOMER []);
    void edit_a_customer(CUSTOMER []);
    void add_money_to_account(CUSTOMER []);
    void withdraw_money_from_account(CUSTOMER []);
    void display_a_customer(CUSTOMER []);
    void display_customer_details(CUSTOMER *);
    void apply_for_overdraft(CUSTOMER []);
    void init_database(CUSTOMER []);
    int  search_database(CUSTOMER [], int);
    int  menu(void);
    
    /* Main Program Scope */
    
    int main (void)
    
    {
        CUSTOMER persons[MAX_PERSONS];
        int menu_choice;
        number==0;
       
        init_database(persons);
       
        do
        {
            menu_choice = menu();
            switch ( menu_choice )
            {
                case 1 : add_a_customer(persons);
                         break;
               
                case 2 : delete_a_customer(persons);
                         break;
               
                case 3 : edit_a_customer(persons);
                         break;
                   
                case 4 : add_money_to_account(persons);
                         break;
               
                case 5 : withdraw_money_from_account(persons);
                         break;
               
                case 6 : display_a_customer(persons);
                         break;
            }
           
        }
        while ( menu_choice != 0);
        return 0;
    }
       
         /* Menu Display */
    
     
    
            /*------------------------------------------------------------------------------------/    
                    | Function: Display A Menu                                                                     |
                    |                                                                                                            |
                    | Purpose: Display A Menu For The Customer To Make A Choice              |
                    |                                                                                                            |
                    | Arguements: Calls A Function When Choice Is Made                             |
                    |--------------------------------------------------------------------------------------*/
       
       
    int menu(void)
    {
            int choice;
          
            /*Display the menu to the user*/
            printf("1.  Add an account.\n\n");
            printf("2.  Delete an account.\n\n");
            printf("3.  Edit an account.\n\n");
            printf("4.  Add money into an account\n\n");
            printf("5.  Withdraw money from an account\n\n");
            printf("6.  Display Customer Details\n\n");
            printf("7.  End Program\n\n");
          
            do
            {
                scanf("%d",&choice);
                fflush(stdin);
            } while( choice < 0 || choice > 9 );
          
            return choice;
    }
       
            /* Case 1 */
       
            /*------------------------------------------------------------------------------------/
                    | Function: Add A Customer                                                                    |
                    |                                                                                                            |
                    | Purpose: Add A Customer To The Banking System                                 |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
       
        void add_a_customer(CUSTOMER person_array[])
        {
            int i=0;
           
            /*Search The Array For Empty Slot.
                        An Empty Slot = 0                        */
           
            while ( person_array[i]. number !=0 && i < MAX_PERSONS )
                i++;
                if ( i > MAX_PERSONS)
                    printf(" Unfortunatly The Database Is Full!!\n");
                else                                                   /* Add To Database */
                {
                    printf("\n\nPlease Choose An Account Number You Will Remember(4 Digits Except 0) : ");
                    do
                        scanf( "%4d",&person_array[i].number);
                    while (person_array[i].number<=0);
                       
                   
                    /*Customer Details Gender */
                    printf("\nCustomer Gender : " );
                    scanf ("%7s",person_array[i].gender);
                   
                       
                    /*Customer Details Name */
                    printf("\nCustomer Surname (Maximum 25 Characters) : " );
                    scanf ("%25s",person_array[i].surname);
                    printf("\nFirst Name (Maximum 25 Characters) : " );
                    scanf ("%25s",person_array[i].first_name);
                   
                    /*Customer Details Date Of Birth */
                   
                    printf("\nDate Of Birth In Format DD/MM/YY\n" );
                    printf("\nDay (1 Or 2 Digits) ; ");
                    scanf ("%4d",&person_array[i].dob.day);
                    printf("\nMonth (1 Or 2 Digits ; ");
                    scanf ("%4d",&person_array[i].dob.month);
                    printf("\nYear (1 Or 2 Digits ; ");
                    scanf ("%4d",&person_array[i].dob.year);
                   
                    /*Customer Details Occupation */
                   
                    printf("\nOccupation (Max 50 Characters):");
                    scanf("%20s",person_array[i].occupation);
                                   
                    /*Customer Details Address */
                    printf("\nAddress Of Customer (max 50 chars):\n");
                    scanf("%50s", person_array[i].address);
                
                        
                }
               
            }
           
            /* Case 2 */
           
            /*------------------------------------------------------------------------------------/
                    | Function: Delete A Customer                                                                |
                    |                                                                                                            |
                    | Purpose:Delete A Customer From The Banking System                           |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
                   
            void delete_a_customer(CUSTOMER person_array[])
           
            {
                int CUSTOMER_number;
                int pos;
               
            /* A Customer Is Deemed Deleted By Placing A 0 In The Customer Number */
               
            /* First The Customer Number Has To Be Obtained */
            printf(" Please Enter Your Personal Number : ");
           
                           
            scanf("%10d",&CUSTOMER_number);
           
              
            pos = search_database(person_array,CUSTOMER_number);
          
            if(pos == MAX_PERSONS)                    /* Yes */         
                printf("This Customer is not in the database\n");
            else                                      /* No */         
            {
                printf("Customer Account number %10d is deleted.\n",CUSTOMER_number);
                person_array[pos].number == 0;
            }
        }
       
       
        /* Case 3 */
       
            /*------------------------------------------------------------------------------------/
                    | Function: Edit A Customer                                                                   |
                    |                                                                                                           |
                    | Purpose: Edit A Customer From The Banking System                            |
                    |                                                                                                           |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
        
            void edit_a_customer(CUSTOMER person_array[])
            {
               
            int account_number;
            int i;
            int pos;
                
            pos = search_database(person_array,account_number);    
       
            printf("Customer Account Number to edit: ");
            do
            scanf("%4d",&account_number);
            while(account_number <=0 || account_number > MAX_PERSONS);
           
           
            if(pos==MAX_PERSONS)
            printf("This customer is not in the database\n");
            else
            {
                  /* Customer Name */
            printf("\n\nCustomer Surname (Up to 25 letters): ");
            scanf("%25s",person_array[pos].surname);
               
            printf("\nFirst Name (Up to 10 letters): ");
            scanf("%10s",person_array[pos].first_name);
               
                  /* Customer Date Of Birth */ 
            printf("\nDate of Birth\n");
            printf("\nDay (1-31): ");
            scanf("%d",&person_array[i].dob.day);
            printf("\nMonth (1-12): ");
               
            scanf("%2d",&person_array[i].dob.month);
            printf("\nYear (2 digits i.e. 1990 is 90): ");
            scanf("%2d",&person_array[i].dob.year);
               
            printf("\nOverdraft Taken (Yes or No): ");
               
            scanf("%3s",person_array[i].overdraft);
           
              
            printf("\nBalance: ");
            scanf("%d",&person_array[i].balance);
            printf("\n\n");
           
            }
       
        }
    
            /* Case 4 */
    
            /*------------------------------------------------------------------------------------/
                    | Function: Add Money To An Account                                                   |
                    |                                                                                                           |
                    | Purpose: Add Money To A Customers Account                                      |
                    |                                                                                                           |
                    |                                                                                                           |
                    |--------------------------------------------------------------------------------------*/
    
     
    
            void add_money_to_account(CUSTOMER [])
    
            {
               
            float add_sum;
            char dummy;
               
            printf("\nThe current balance for %s is %c%4.2f",account[current].name,156,
            account[current].balance);
               
            printf("\nHow much do you want to add to the account? %c",156);
            dummy=getch(); /* Clear Out Input Buffer */
               
            scanf("%f",&add_sum);
            if(add_sum < 0)
            {
            printf("\nNo negative sums allowed here");
            return;
            }
            account[current].balance += add_sum;
            printf("\nThe new balance is %c%4.2f",156,account[current].balance);
            return;
            }
    
    
            /* Case 5 */
    
            /*------------------------------------------------------------------------------------/
                    | Function: Withdraw Money From An Account                                      |
                    |                                                                                                           |
                    | Purpose: Withdraw Money From A Customers Account                         |
                    |                                                                                                           |
                    |                                                                                                            |
                    |--------------------------------------------------------------------------------------*/
    
                void withdraw_money_from_account(CUSTOMER[])
           
            {
               
            float take_sum;
            char dummy;
               
            printf("\nThe current balance for %s is %c%4.2f",account[current].name,156,
            account[current].balance);
               
            if(account[current].balance == 0)
            {
               
            printf("\nThis account has zero balance - no overdraft facility!");
            return;
               
            }
           
            printf("\nHow much do you want to take from the account? %c",156);
            dummy=getch();//clear out input buffer
            scanf("%f",&take_sum);
           
            if(take_sum < 0)
            {
               
            printf("\nNo negative sums allowed here");
            return;
               
            }
           
            if(take_sum > account[current].balance)
               
            {
               
            printf("\nInsufficient funds!");
            return;
               
            }
           
            account[current].balance -= take_sum;
            printf("\nThe new balance is %c%4.2f",156,account[current].balance);
           
            }
           
                   
                
    
            /* Case 7 */
       
            /*------------------------------------------------------------------------------------/    
                    | Function: Search Database                                                                  |
                    |                                                                                                            |
                    | Purpose: Search Database For Customer                                               |
                    |                                                                                                            |
                    |                                                                                                            |
                    |--------------------------------------------------------------------------------------*/
            
            int search_database(CUSTOMER person_array[], int account_number)
            {
               
            int i =0;
    
            while (i<MAX_PERSONS && person_array[i].number != account_number)
            {
            i++;
            }
            return (i);
           
            }
       
    
            /* Case 8 */
       
            /*------------------------------------------------------------------------------------/
                    | Function: Display A Customer                                                               |
                    |                                                                                                            |
                    | Purpose: Display A Customer From The Banking System                         |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customer Array                                     |
                    |--------------------------------------------------------------------------------------*/
       
        void display_a_customer( CUSTOMER person_array[] )
        {
            int CUSTOMER_number;
            int pos;
       
            /* Get The Customer Number */
            printf(" Customer Number To Display ( 1-4 Digits, Except 0) :");
            do
                scanf("%4d",&CUSTOMER_number);
                while( CUSTOMER_number <= 0);
                   
                /* Find The Customer In The Database */
                pos = search_database( person_array,CUSTOMER_number);
               
                /* Does The Customer Exist In The Databse */
                if ( pos == MAX_PERSONS) /* No */
                printf(" The Selected Customer Is Not In The Databse\n" );
                else                     /* Yes - Display The Details */
                    display_customer_details(&person_array[pos]);
            }
           
            /*------------------------------------------------------------------------------------/
                    | Function: Display A Customers Details                                                  |
                    |                                                                                                            |
                    | Purpose: Display A Customers Details From The Banking System            |
                    |                                                                                                            |
                    | Arguements: A Pointer To The Customers Details                                  |
                    |--------------------------------------------------------------------------------------*/
           
            void display_customer_details(CUSTOMER *ptr)
        {
            printf("\n\n");
            printf("Account number : %d\n",ptr->number);
            printf("Surname        : %s\n",ptr->surname);
            printf("Firstname      : %s\n",ptr->first_name);
            printf("Occupation     : %s\n",ptr->occupation);
            printf("Surname        : %s\n",ptr->surname);
            printf("Date of Birth  : %2d/%2d/%2d\n",ptr->dob.day, ptr->dob.month, ptr->dob.year);
            printf("Address        : %50s\n",ptr->address);
        };
        
            /*------------------------------------------------------------------------------------/
                    | Function: Initialise The Database                                                        |
                    |                                                                                                            |
                    | Purpose: Starts The Database                                                              |
                    |                                                                                                            |
                    |                                                                                                            |
                    |--------------------------------------------------------------------------------------*/
        
        void init_database(CUSTOMER person_array[])
        {
            int i;
           
            for(i=0;i<MAX_PERSONS;i++)
            {
                person_array[i].number == 0;
            }
           
        }

  13. #13
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Well I am not exactly sure what the problem is but I think it's related to the following things:

    1) Don't use scanf to read strings. Use fgets() instead.

    2) i should be incremented at the end of the loop

    3) You should have a way so that you always add new customers to the end of your array. You should keep track of the number of customers you currently have. If you currentCustomerNumber < MAX then you still have space for more customers.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    i just copied and compiled this... there's more than one error to deal with...

    Code:
    Building main.obj.
    E:\c_Code\Experiments\consoleprog\main.c(46): error #2199: Invalid field declaration after empty field in '(incomplete) struct personnel'.
    E:\c_Code\Experiments\consoleprog\main.c(289): warning #2234: Argument 2 to 'scanf' does not match the format string; expected 'char *' but found 'int'.
    E:\c_Code\Experiments\consoleprog\main.c(314): error #2094: Missing name for parameter 1 to function 'add_money_to_account'.
    E:\c_Code\Experiments\consoleprog\main.c(323): warning #2027: Missing prototype for 'getch'.
    E:\c_Code\Experiments\consoleprog\main.c(349): error #2094: Missing name for parameter 1 to function 'withdraw_money_from_account'.
    E:\c_Code\Experiments\consoleprog\main.c(366): warning #2027: Missing prototype for 'getch'.
    *** Error code: 1 ***

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    When I compile your code I get these errors and warnings.

    main.c|45|error: flexible array member not at end of struct|
    main.c||In function ‘main’:|
    main.c|72|warning: statement with no effect|
    main.c|79|warning: switch missing default case|
    main.c||In function ‘delete_a_customer’:|
    main.c|242|warning: statement with no effect|
    main.c||In function ‘edit_a_customer’:|
    main.c|295|warning: format ‘%3s’ expects type ‘char *’, but argument 2 has type ‘int’|
    main.c||In function ‘add_money_to_account’:|
    main.c|318|error: parameter name omitted|
    main.c||In function ‘withdraw_money_from_account’:|
    main.c|353|error: parameter name omitted|
    main.c|363|warning: comparing floating point with == or != is unsafe|
    main.c|473|error: ISO C does not allow extra ‘;’ outside of a function|
    main.c||In function ‘init_database’:|
    main.c|489|warning: statement with no effect|
    You seem to be using the comparison operator "==" where you should be using the assignment operator "=" in several places. In your structure definition you have an array variable with the brackets [] but no size, this needs the size or remove the brackets for a plain char. You have a couple of functions where you have left off the variable type for a parameter.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2009, 01:49 AM
  2. I cant figure out how to fix this error
    By Raigne in forum C++ Programming
    Replies: 4
    Last Post: 11-28-2005, 02:04 AM
  3. can't figure this error out
    By the Wookie in forum C++ Programming
    Replies: 4
    Last Post: 07-08-2003, 03:23 PM
  4. getting an error I can't figure out....
    By Soopafly in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2002, 09:30 AM
  5. Can't figure it out the error??? HELP!!!
    By xeneize in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2002, 03:44 PM