I've already said this once, and it's starting to get repetitive: USE [CODE] TAGS!
Quzah.
Printable View
I've already said this once, and it's starting to get repetitive: USE [CODE] TAGS!
Quzah.
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?
I *thought* I did that already. :D
Consider:
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!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]);
}
}