A few comments to your program.
Code:
char vitamin_string_name[100];
The name of the variable makes me think that you want a string instead of a char. like this
Code:
char vitamin_string_name[100][20];// 100 names with max 19 chars
Code:
double totalvalue( void ); // will calculate total value for one vitamin
This doesn't work. This function has to know witch vitamins totalvalue to calculate.
I would use this prototype
Code:
double totalvalue( int idx ); // will calculate total value for one vitamin
why do you use double for the total number of jars ( you won't have half a jar )
Code:
int vitamin_count = 0; // total number of jars in the inventory
and you should update vitamin_count in the input loop.
Code:
//for ( j = 0; j == i; j++ ){ // this way your loop will never be entered
for ( j = 0; j < vitamin_count; j++ ){ // better
cout << vitamin_string_name[j] << setw( 14 )<< unit_price[j] << setw( 9 ) << num_of_jars[j] << setw( 15 ) << totalvalue(j) << endl; // you want to call totalvalue
} // that one is missing
I haven't gotten to the average portion yet.
That one should be easy. Just loop over the unit_price from 0 to vitamin_count -1 add them all up and divide the result by vitamin_count.
BTW the whole thing would be a lot easier if you would use a struct.
e.g.
Code:
struct vitamin {
char [20] name;
double unit_price;
int quantity;
};
and declare inventory as
Code:
struct vitamin[100] inventory;
This way you could easily get rid of all the global variables by passing that array and the number of items in the inventory to the functions totalvalue() and average()