CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    4

    Unhappy compiling problem

    this program is not compiling. can anyone tell me the problems in this program with the solutions.
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #define MAX=999
    int i;
    int id;
    
    struct customer {
     char custID[20];
     char name[50];
     char address[80];
     char tell[15];
     float credl; 
    };
    int add_Name ();
    int menu_Display ();
    int get_Menu ();
    int get_Option ();
    int cust_id();
     int cust_Name();
    
    
    int main()
    {
        
        menu_Display ();
        get_Menu ();
        get_Option ();
        
        getch();
     return 0;
     
    }
    int menu_Display () {
         int choice=0;
         while (choice!=6) {
               get_Menu ();
               choice = get_Option();
               }}
    int get_Menu (){
        int i;
        for (i=0; i<1; i++) {
        printf ("\t1. Display information of all customers\n\n");
        printf ("\t2. Search for customer by Name\n\n");
        printf ("\t3. Search for customer by ID\n\n");
        printf ("\t4. Display a list of customers having credit limit above 5,000\n\n");
        printf ("\t5. Add new customer\n\n");
        printf ("\t6. Exit\n\n");
    }
        
    }
    int get_Option () {
        
        int option;
        printf ("Please enter your option...");
        scanf ("%d", &option);
    }
    int menu_Option (int option) {
        int i;
        switch (option) {
               case 1 : cust_Name();
               break;
               case 2 : cust_id();
               break;
               case 3 : add_Name();
               break;
               case 6 : printf("The program will now exit\n");
               break;
               default : printf ("Sorry that does not exist");
               i=getchar();
               break;
               }
               }
    
    
    int add_Name () {
     int i;
     struct customer xrecord[200];
     for (i=0;i<1;i++)
     {
      strcpy(xrecord[i].custID,"ID00");
      //strcpy(xrecord[i].custID,(strcat(xrecord[i].custID,i));
      printf("Enter Name:");
      scanf("\n%s",&(xrecord[i].name)) ;
      printf("Enter address:");
      printf ("\n");
      scanf("\n%s",&(xrecord[i].address));
      printf("Enter tell:");
      scanf("\n%s",&(xrecord[i].tell));
      printf("Enter credl:"); 
      scanf("\n%f",&(xrecord[i].credl));
      
    }
      
     }
     int cust_Name() {
        int match;
        int i;
        int result;
        int loop=0;
        char name[20];
        
        printf("Please enter the name which you are searching for\n");
        gets(name);
        while (match == 0 && i < MAX) {
              result= strcmp(all_names[loop].name,name);
              loop++;
              }
              if (loop == MAX) {
                       printf ("Match not found\n");
                       }
              i=getchar();
              }
     int cust_id() {
        int match;
        int i;
        int result=0;
        int loop=0;
        int id;
        
        printf ("Please enter the id number which you are searching for\n");
        scanf ("%d", &id);
        while (match == 0 && i< MAX) {
              result = strcmp (all_names[loop].id,id);
              loop++;
              }
              if (loop == MAX) {
                       printf ("Match not found");
                       }
              i = getchar();
              }

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: compiling problem

    You have error messages, don't you?

    Usually, when a function has zero argument, I write void between the parenthesis. I don't know if this is the problem.

    int menu_Display () {
    -->
    int menu_Display (void) {

    When a function is supposed to return an integer, e.g. get_Option(void), int cust_id(void), et.c, then have at least one line in it with return option; or return an_integer;.

  3. #3
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: compiling problem

    this program is not compiling. can anyone tell me the problems in this program with the solutions.
    It is good that you posted your code in code tags, but you should do two more things:
    • Indent the code more consistently.
    • Post the error messages, including the line numbers.

    If this is intended to be C rather than C++, you should also state as such.

    Quote Originally Posted by olivthill2
    Usually, when a function has zero argument, I write void between the parenthesis. I don't know if this is the problem.
    It is not, though it should be done in C for forward declarations of functions that have no parameters.

    At a glance, one problem lies here:
    Code:
    #define MAX=999
    It should be:
    Code:
    #define MAX 999
    Other things to take note of:
    • <conio.h> is non-standard and you probably do not need it anyway.
    • Avoid global variables.
    • Never use gets() unless you must use it and can absolutely guarantee that the input will be correct (e.g., it is a programming contest) since it is inherently vulnerable to buffer overflow.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #4
    Join Date
    Jan 2003
    Posts
    615

    Re: compiling problem

    In the below code the variable all_names is not defined and the function strcmp requires two parameters of type const char *.
    Code:
    int id;
    result = strcmp (all_names[loop].id,id);
    http://www.cplusplus.com/reference/c...string/strcmp/

    Also, I believe getch is an C API and not use in C++.
    Before post, make an effort yourself, try googling or search here.

    When posting, give a proper description of your problem, include code* and error messages.

    *All code should include code tags

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: compiling problem

    In addition to the MAX problem already pointed out, I get
    error C2065: 'all_names' : undeclared identifier

    That seems pretty self-explanatory.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured