Thread: help with array

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    29

    help with array

    Code:
    #define num 4
    #define length 100
    #include<stdio.h>
    void fiction();
    void art();
    void engin();
    void child();
    void study();
    void display(float p,char books[][],price[]);
    int main()
    {
        char option,ans,wey;
        float total=0.0,a=0.0,b=0.0,c=0.0,d=0.0,e=0.0;
        printf("WELCOME TO ONLINEBUKU.COM\n\a");
        printf("WHICH CATEGORY YOU WANT TO CHOOSE?\n");
        printf("   A: FICTION BOOKS\n");
        printf("   B: ART AND CRAFT BOOKS\n");
        printf("   C: ENGINEERING & SCIENCE BOOKS\n");
        printf("   D: CHILDREN BOOKS\n");
        printf("   E: ISLAMIC STUDIES BOOKS\n");
        do
        {
           printf("\n");
           printf("YOUR OPTION:\a");
           scanf("%c",&option);
           printf("\n");   
           switch(option)
          {
           case 'A': a=fiction(q);break;
           case 'a': a=fiction(q);break;
           case 'B': b=art(v);break;
           case 'b': b=art(v);break;
           case 'C': c=engin(w);break;
           case 'c': c=engin(w);break;
           case 'D': d=child(x);break;
           case 'd': d=child(x);break;
           case 'E': e=study(y);break;
           case 'e': e=study(y);break;
                
         }
         
          total= a+b+c+d+e; 
          fflush(stdin);
          printf("\tPress Y to continue:\a");
          scanf("%c",&ans);     
          fflush(stdin);
        }while(ans=='Y'||ans=='y');
       
        
        display(total);
        system("pause");
        return 0;
    }
    void fiction()
     {
        char books[num][length]={"Zeus King Of The Gods","Penny Century","Map of the Invisible World","Jodi Picoult: House Rules"};
        char wey;
        float price[num]={ 58.20,78.90,34.60,32.90 };
        float total=0.0;
         do
         {    
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION A: FICTION BOOKS  \t\t PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Zeus King Of The Gods                  RM  58.20\n");
          printf("\t2.Penny Century                          RM  78.90\n");
          printf("\t3.Map of the Invisible World             RM  34.60\n");
          printf("\t4.Jodi Picoult: House Rules              RM  32.90\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          for( i=0 ; i<4 ; i++ )
          {
               total+=price[i]*amount;
          }  
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
         display(total,char books[i][length],price[i]);
          
          
    }  
     void art()
     {
           char books[num][length]={"Connoisseur'S Guide To Antique Silver","Best Ever Craft Project Book","Encyclopedia Of Acrylic Techni Ques","Teach Yourself Calligraphy"};
           char wey;
           float price[num]={58.20,38.50,89.60,100.50};
           float total= 0.0;
           do
          {
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION B: ART AND CRAFT BOOKS  \t\tPRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Connoisseur'S Guide To Antique Silver  RM  58.20\n");
          printf("\t2.Best Ever Craft Project Book           RM  38.50\n");
          printf("\t3.Encyclopedia Of Acrylic Techni Ques    RM  89.60\n");
          printf("\t4.Teach Yourself Calligraphy             RM 100.50\n");
           printf("\tPlease key in your choice:");
          scanf("%d",&books);
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          for( i=0 ; i<4 ; i++ )
          {
               total+=price[i]*amount;
          }  
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
          display(total,char books[i][length],price[i]);
          
          
     }
     void engin()
     {
           char books[num][length]={"Solar Power For Your Home","Chemical Engineering Thermodynamic","Marine Electrical Technology","Engineering Design Reliability"};
           char wey;
           float price[num]={71.80,69.90,128.60,112.90};
           float total= 0.0;
           do
           {
         
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION C: ENGINEERING & SCIENCE BOOKS  PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Solar Power For Your Home             RM  71.80\n");
          printf("\t2.Chemical Engineering Thermodynamic    RM  69.90\n");
          printf("\t3.Marine Electrical Technology          RM 128.60\n");
          printf("\t4.Engineering Design Reliability        RM 112.90\n");
           printf("\tPlease key in your choice:");
          scanf("%d",&books);
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
         for( i=0 ; i<4 ; i++ )
          {
               total+=price[i]*amount;
          }  
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
         display(total,char books[i][length],price[i]);
          
          
     }
     void child()
     {
         char books[num][length]={"Kasih Sahabat","Adikku Istimewa","101 Akhlak Rasulullah","Legasi Blok E: Kebangkitan Kuasa"};
         char wey;
         float price[num]={11.90,12.00,32.00,14.50};
         float total= 0.0;
         do
         {
           
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION D: CHILDREN BOOKS  \t    PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1. Kasih Sahabat                      RM  11.90\n");
          printf("\t2. Adikku Istimewa                    RM  12.00\n");
          printf("\t3. 101 Akhlak Rasulullah              RM  32.00\n");
          printf("\t4. Legasi Blok E: Kebangkitan Kuasa   RM  14.50\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          for( i=0 ; i<4 ; i++ )
          {
               total+=price[i]*amount;
          }  
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
        
        display(total,char books[i][length],price[i]);
          
          
     }
     void study()
     {
         char books[num][length]={"Mencari Islam di China","From Cat Steven to Yusuf Islam","Ketika Hatiku Ingin Berhijrah","Taatilah Allah, Rasul & Ulil Amri"};
         char wey;
         float price[num]={23.30,20.00,25.50,12.50};
         float total= 0.0;
         do
         {
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION E: ISLAMIC STUDIES BOOKS \tPRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1. Mencari Islam di China               RM  23.30\n");
          printf("\t2. From Cat Steven to Yusuf Islam       RM  20.00\n");
          printf("\t3. Ketika Hatiku Ingin Berhijrah        RM  25.50\n");
          printf("\t4. Taatilah Allah, Rasul & Ulil Amri    RM  12.50\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          for( i=0 ; i<4 ; i++ )
          {
               total+=price[i]*amount;
          }  
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
         display(char books[i][length],price[i]);
          
         
     }
     void display(float p,char books[][],price[])
     {
          printf("\n");
          printf("\t~~~~~~~~~~~~~~~ONLINEBUKU PAYMENT RECEIPT~~~~~~~~~~~~~~~\n");
          printf("\n");
          printf("\t\tTitle\t\tPrice\t\tTotal\n");
          printf("\t\t%s\t\t%f\t\t%f\n",char books[][],price[],p);
          printf("\n");
    }
    why the compiler kept displaying
    In function `main':
    void value not ignored as it ought to be
    In function eg:'study'':
    syntax error before "char"
    At top level:
    syntax error before "price"
    In function `display':
    syntax error before "char"

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Maybe you should read your book on how functions work? A function that returns void ... returns nothing at all that can be assigned to a variable.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    29

    change

    Code:
    #define num 4
    #define length 100
    #include<stdio.h>
    void fiction();
    void art();
    void engin();
    void child();
    void study();
    void display(char books[num][length],float price[num]);
    int main()
    {
        char option,ans,wey;
        float sum=0.0,a=0.0,b=0.0,c=0.0,d=0.0,e=0.0;
        printf("WELCOME TO ONLINEBUKU.COM\n");
        printf("WHICH CATEGORY YOU WANT TO CHOOSE?\n");
        printf("   A: FICTION BOOKS\n");
        printf("   B: ART AND CRAFT BOOKS\n");
        printf("   C: ENGINEERING & SCIENCE BOOKS\n");
        printf("   D: CHILDREN BOOKS\n");
        printf("   E: ISLAMIC STUDIES BOOKS\n");
        do
        {
           printf("\n");
           printf("YOUR OPTION:");
           scanf("%c",&option);
           printf("\n");   
           switch(option)
          {
           case 'A': fiction();break;
           case 'a': fiction();break;
           case 'B': art();break;
           case 'b': art();break;
           case 'C': engin();break;
           case 'c': engin();break;
           case 'D': child();break;
           case 'd': child();break;
           case 'E': study();break;
           case 'e': study();break;
                
         }
       
       
     
          sum= a+b+c+d+e; 
          fflush(stdin);
          printf("\tPress Y to continue:");
          scanf("%c",&ans);     
          fflush(stdin);
        }while(ans=='Y'||ans=='y');
        printf("The sum is %0.2f",sum);
       
        system("pause");
        return 0;
    }
    void fiction()
     {
        int i; 
        char books[num][length]={"Zeus King Of The Gods","Penny Century","Map of the Invisible World","Jodi Picoult: House Rules"};
        char wey;
        float a=0.0, price[num]={ 58.20,78.90,34.60,32.90 };
        float total=0.0;
         do
         {    
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION A: FICTION BOOKS  \t\t PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Zeus King Of The Gods                  RM  58.20\n");
          printf("\t2.Penny Century                          RM  78.90\n");
          printf("\t3.Map of the Invisible World             RM  34.60\n");
          printf("\t4.Jodi Picoult: House Rules              RM  32.90\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
         
          
               total=price[books]*amount;
                
          display(books[][],price[]);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
    
       
          
          
    }  
    void art()
     {
           int i;
           char books[num][length]={"Connoisseur'S Guide To Antique Silver","Best Ever Craft Project Book","Encyclopedia Of Acrylic Techni Ques","Teach Yourself Calligraphy"};
           char wey;
           float price[num]={58.20,38.50,89.60,100.50};
           float total= 0.0;
           do
          {
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION B: ART AND CRAFT BOOKS  \t\tPRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Connoisseur'S Guide To Antique Silver  RM  58.20\n");
          printf("\t2.Best Ever Craft Project Book           RM  38.50\n");
          printf("\t3.Encyclopedia Of Acrylic Techni Ques    RM  89.60\n");
          printf("\t4.Teach Yourself Calligraphy             RM 100.50\n");
           printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          
               total=price[books]*amount;
               
          display(books[][],price[]);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
       
          
     }
    void engin()
     {
           int i;
           char books[num][length]={"Solar Power For Your Home","Chemical Engineering Thermodynamic","Marine Electrical Technology","Engineering Design Reliability"};
           char wey;
           float price[num]={71.80,69.90,128.60,112.90};
           float total= 0.0;
           do
           {
         
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION C: ENGINEERING & SCIENCE BOOKS  PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Solar Power For Your Home             RM  71.80\n");
          printf("\t2.Chemical Engineering Thermodynamic    RM  69.90\n");
          printf("\t3.Marine Electrical Technology          RM 128.60\n");
          printf("\t4.Engineering Design Reliability        RM 112.90\n");
           printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
     
               total=price[books]*amount;
               
          display(books[][],price[]);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
        
        
          
     }
    void child()
     {
         int i;
         char books[num][length]={"Kasih Sahabat","Adikku Istimewa","101 Akhlak Rasulullah","Legasi Blok E: Kebangkitan Kuasa"};
         char wey;
         float price[num]={11.90,12.00,32.00,14.50};
         float total= 0.0;
         do
         {
           
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION D: CHILDREN BOOKS  \t    PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1. Kasih Sahabat                      RM  11.90\n");
          printf("\t2. Adikku Istimewa                    RM  12.00\n");
          printf("\t3. 101 Akhlak Rasulullah              RM  32.00\n");
          printf("\t4. Legasi Blok E: Kebangkitan Kuasa   RM  14.50\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          
               total=price[books]*amount;
               
          display(books[][],price[]);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
        
      
          
     }
    void study()
     {
         int i;
         char books[num][length]={"Mencari Islam di China","From Cat Steven to Yusuf Islam","Ketika Hatiku Ingin Berhijrah","Taatilah Allah, Rasul & Ulil Amri"};
         char wey;
         float price[num]={23.30,20.00,25.50,12.50};
         float total= 0.0;
         do
         {
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION E: ISLAMIC STUDIES BOOKS \tPRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1. Mencari Islam di China               RM  23.30\n");
          printf("\t2. From Cat Steven to Yusuf Islam       RM  20.00\n");
          printf("\t3. Ketika Hatiku Ingin Berhijrah        RM  25.50\n");
          printf("\t4. Taatilah Allah, Rasul & Ulil Amri    RM  12.50\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
       
               total=price[books]*amount;
               
          display(books[][],price[]);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
       
     }
     void display(char r,float p)
     {
          printf("%s %0.2f",r,p);
    } 
    
     }
     void display(char books[][],price[])
     {
          printf("\n");
          printf("\t~~~~~~~~~~~~~~~ONLINEBUKU PAYMENT RECEIPT~~~~~~~~~~~~~~~\n");
          printf("\n");
          printf("\t\tTitle\t\tPrice\n");
          printf("\t\t%s\t\t%f\n",char books[][],price[]);
          printf("\n");
    }
    i wanted to print a book ordering receipt with this program.but i have this problem in capturing the name of the book and also its price to be displayed in display function.how to use the array actually? can someone teach me? then to total up the price..do i need to use non void to return the value to main and calculate it in the main program?

  4. #4
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    don't use fflush(stdin)..it isn't meant to work on stdin. Will result in undefined behavior.
    You ended that sentence with a preposition...Bastard!

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > void display(float p,char books[][],price[]);
    The minor dimension of books cannot be empty.

    Something like
    void display(float p,char books[][SOME_SIZE],price[]);

    > display(books[][],price[]);
    To call a function, it is just the array name (no empty [ ] )
    Like so
    display(books,price);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    29
    in every function.the compiler says
    syntax error before ']' token..what does this mean?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    No idea, without seeing your latest code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by amoeba532 View Post
    in every function.the compiler says
    syntax error before ']' token..what does this mean?
    It means your code has confused the compiler.

    My guess is that you haven't fully fixed the concerns pointed out in Salem's post (#5).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Registered User
    Join Date
    Nov 2010
    Posts
    29
    Code:
    #define num 4
    #define length 100
    #include<stdio.h>
    void fiction();
    void art();
    void engin();
    void child();
    void study();
    void display(char r,float p);
    int main()
    {
        char option,ans,wey;
        float sum=0.0,a=0.0,b=0.0,c=0.0,d=0.0,e=0.0;
        printf("WELCOME TO ONLINEBUKU.COM\n");
        printf("WHICH CATEGORY YOU WANT TO CHOOSE?\n");
        printf("   A: FICTION BOOKS\n");
        printf("   B: ART AND CRAFT BOOKS\n");
        printf("   C: ENGINEERING & SCIENCE BOOKS\n");
        printf("   D: CHILDREN BOOKS\n");
        printf("   E: ISLAMIC STUDIES BOOKS\n");
        do
        {
           printf("\n");
           printf("YOUR OPTION:");
           scanf("%c",&option);
           printf("\n");   
           switch(option)
          {
           case 'A': fiction();break;
           case 'a': fiction();break;
           case 'B': art();break;
           case 'b': art();break;
           case 'C': engin();break;
           case 'c': engin();break;
           case 'D': child();break;
           case 'd': child();break;
           case 'E': study();break;
           case 'e': study();break;
                
         }
       
       
     
          sum= a+b+c+d+e; 
          fflush(stdin);
          printf("\tPress Y to continue:");
          scanf("%c",&ans);     
          fflush(stdin);
        }while(ans=='Y'||ans=='y');
        printf("The sum is %0.2f",sum);
       
        system("pause");
        return 0;
    }
    void fiction()
     {
        int i; 
        char books[num][length]={"Zeus King Of The Gods","Penny Century","Map of the Invisible World","Jodi Picoult: House Rules"};
        char wey;
        float a=0.0, price[num]={ 58.20,78.90,34.60,32.90 };
        float total=0.0;
         do
         {    
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION A: FICTION BOOKS  \t\t PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Zeus King Of The Gods                  RM  58.20\n");
          printf("\t2.Penny Century                          RM  78.90\n");
          printf("\t3.Map of the Invisible World             RM  34.60\n");
          printf("\t4.Jodi Picoult: House Rules              RM  32.90\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
         
          
               total=price[books]*amount;
                
          display(books,price);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
    
       
          
          
    }  
    void art()
     {
           int i;
           char books[num][length]={"Connoisseur'S Guide To Antique Silver","Best Ever Craft Project Book","Encyclopedia Of Acrylic Techni Ques","Teach Yourself Calligraphy"};
           char wey;
           float price[num]={58.20,38.50,89.60,100.50};
           float total= 0.0;
           do
          {
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION B: ART AND CRAFT BOOKS  \t\tPRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Connoisseur'S Guide To Antique Silver  RM  58.20\n");
          printf("\t2.Best Ever Craft Project Book           RM  38.50\n");
          printf("\t3.Encyclopedia Of Acrylic Techni Ques    RM  89.60\n");
          printf("\t4.Teach Yourself Calligraphy             RM 100.50\n");
           printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          
               total=price[books]*amount;
               
          display(books,price);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
       
          
     }
    void engin()
     {
           int i;
           char books[num][length]={"Solar Power For Your Home","Chemical Engineering Thermodynamic","Marine Electrical Technology","Engineering Design Reliability"};
           char wey;
           float price[num]={71.80,69.90,128.60,112.90};
           float total= 0.0;
           do
           {
         
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION C: ENGINEERING & SCIENCE BOOKS  PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1.Solar Power For Your Home             RM  71.80\n");
          printf("\t2.Chemical Engineering Thermodynamic    RM  69.90\n");
          printf("\t3.Marine Electrical Technology          RM 128.60\n");
          printf("\t4.Engineering Design Reliability        RM 112.90\n");
           printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
     
               total=price[books]*amount;
               
          display(books,price);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
        
        
          
     }
    void child()
     {
         int i;
         char books[num][length]={"Kasih Sahabat","Adikku Istimewa","101 Akhlak Rasulullah","Legasi Blok E: Kebangkitan Kuasa"};
         char wey;
         float price[num]={11.90,12.00,32.00,14.50};
         float total= 0.0;
         do
         {
           
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION D: CHILDREN BOOKS  \t    PRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1. Kasih Sahabat                      RM  11.90\n");
          printf("\t2. Adikku Istimewa                    RM  12.00\n");
          printf("\t3. 101 Akhlak Rasulullah              RM  32.00\n");
          printf("\t4. Legasi Blok E: Kebangkitan Kuasa   RM  14.50\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
          
               total=price[books]*amount;
               
          display(books,price);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
        
      
          
     }
    void study()
     {
         int i;
         char books[num][length]={"Mencari Islam di China","From Cat Steven to Yusuf Islam","Ketika Hatiku Ingin Berhijrah","Taatilah Allah, Rasul & Ulil Amri"};
         char wey;
         float price[num]={23.30,20.00,25.50,12.50};
         float total= 0.0;
         do
         {
          int books,amount,i;
          float total=0.0;
          printf("\tOPTION E: ISLAMIC STUDIES BOOKS \tPRICE (UNIT)\n");
          printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
          printf("\t1. Mencari Islam di China               RM  23.30\n");
          printf("\t2. From Cat Steven to Yusuf Islam       RM  20.00\n");
          printf("\t3. Ketika Hatiku Ingin Berhijrah        RM  25.50\n");
          printf("\t4. Taatilah Allah, Rasul & Ulil Amri    RM  12.50\n");
          printf("\tPlease key in your choice:");
          scanf("%d",&books);
          books--;
          printf("\tPlease enter the amount:");
          scanf("%d",&amount);
       
               total=price[books]*amount;
               
          display(books,price);
          printf("\tThe total price is RM%0.2f\n",total);
          printf("\tEnter R if you want to choose within the same category:");
          scanf("%s", &wey); 
          printf("\n");
        }while(wey=='r' ||wey=='R');
         
       
     }
     void display(char r,float p)
     {
          printf("\t\t%s\t\tRM %0.2f\n",r,p);
    }
    done.but then the compiler displayed
    incompatible type for argument 2 of `display'.??
    Last edited by amoeba532; 01-29-2011 at 02:48 PM. Reason: new

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    display() expects two values (a char and a float). When you call it, you are passing arrays.

    Are you actually trying to reason things out on your own? Or are you just posting here as soon as you get an error message without any thought? It strikes me - given the timing between your posts - that you are doing the latter - which means you are wasting your time and ours.

    Error messages from compilers may be cryptic, but they always include some hints (eg line numbers) about where the problems are. You will learn more by reasoning things out on your own - and become self sufficient.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multidimensional Array Addressing
    By BlackOps in forum C Programming
    Replies: 11
    Last Post: 07-21-2009, 09:26 PM
  2. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM