Thread: confused about arrays

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I've already said this once, and it's starting to get repetitive: USE [CODE] TAGS!

    Quzah.
    Hope is the first step on the road to disappointment.

  2. #17
    Registered User
    Join Date
    Sep 2004
    Posts
    17
    Ronin,
    Is what i want to do, to
    1.get the number of books in stock for each category
    2. go through category(1) and get the avg price
    3.go through category(1) and get sell percentage

    so that I'll get this when i printout
    Category Stock Avg_Price Sell_Percent
    Cookbooks 100 11.25 25
    History 250 9.99 35
    ......... ...... ........ ......
    ......... ....... .......... .......
    Max[10] >>>> >>>>> >>>>

    does this help any?
    Any one please help me?
    Down to the last wire?

  3. #18
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    I *thought* I did that already.

    Consider:

    Code:
    
    #include <stdio.h>
    
    #define MAXB 5
    
    const char BOOKS[][18]  =  { "Automobile", "Cook",
                                 "Gardening",  "History",
                                 "Mystery" };
    
    int getIndex(void);
    void requestInput(int, int [],  int [], float []);
    void pushData(int [], int [], float [], int []);
    
    int main(void)
    {
       
        int index, done, invt[MAXB],
                        sellp[MAXB],
                        check[MAXB] = { 0 };
                        
        float avep[MAXB];
    
        done = 0;
    
        while(done < MAXB)
        {
           index = getIndex() - 1; 
            
           if(index == 5)
              done = MAXB;
           
           else   
           {
    
              if(check[index] == 0)
              { 
                   requestInput(index, invt, sellp, avep);
                   check[index] = 1;
                   done++;
              }
           
              else
                 puts("\nContains data already.\n");        
           }
        }   
    
        pushData(invt, sellp, avep, check); 
        puts("\nDone.");
    
        return (0);
    }
    
    int getIndex(void)
    {
       int i;
       static char myprompt[] = "1) Automobile\n2) Cook\n3) Garden\n"
                                "4) History\n5) Mystery\n6) Quit\n\n--> ";
    
       do
       {
           fflush(stdout);
           puts("\nSelect a book category (1-6) \n");
           printf("%s", myprompt);
           scanf(" %d", &i);
    
       }while(i < 1 || i > 6);
    
        return (i);
    }
    
    void requestInput(int i, int a[], int b[], float c[])
    {
        printf("\nEnter number of %s books: ", BOOKS[i]);
        scanf(" %d", &a[i]);
    
        printf("Enter the sell percentage of %s books: ", BOOKS[i]);
        scanf( "%d", &b[i]);
    
        printf("Enter the ave price for %s books: ", BOOKS[i]);
        scanf(" %f", &c[i]);
    }
    
    void pushData(int a[], int b[], float c[], int d[])
    {
        int i;
    
        puts("\nCategory  Stock  Avg_Price  Sell_Percent\n");
    
        for(i=0; i < MAXB; i++)
        {
          if(d[i] == 1)
             printf("%s\t%d\t%.2f\t%d\n", BOOKS[i], a[i], c[i], b[i]);
        }
    }
    
    You can play around with that, and see if it will help you... dunno how many bugs it has though. Use at your own risk!
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vertex Arrays
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 01-08-2006, 01:24 AM
  2. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  3. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  4. Help with arrays and pointers please...
    By crazyeyesz28 in forum C++ Programming
    Replies: 8
    Last Post: 03-17-2005, 01:48 PM
  5. Merging two arrays.
    By Roaring_Tiger in forum C Programming
    Replies: 2
    Last Post: 08-21-2004, 07:00 AM