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!