# Basic Array question

• 12-15-2011
iGuardian
Basic Array question
For some reason when I run the program I output hexidecimals. Can anyone help me with this and point me in the right direction?
Code:

```#include <iostream>#include <cstdlib> #include <fstream> #include <iomanip> #include <cmath> using namespace std; // Function Prototypes void getInput(string varray[], string vitamin, double parray[], double price, int qarray[], int quantity); void totalValue(double price, int quantity, double totalvalue); void averageValue(double price, int quantity, double avgValue); void printTable(string varray[], string vitamin, double parray[], double price, int qarray[], int quantity, double totalvalue); int main() {     // Declares the variables.     string vitamin;     double price, totalvalue, avgValue;     int quantity, size;         // Sets the array sizes to 3.     string Varraysize[3] = {};     double Parraysize[3] = {};     int Qarraysize [3] = {};     // Function Calls     getInput(Varraysize, vitamin, Parraysize, price, Qarraysize, quantity);     totalValue(price,quantity, totalvalue);     averageValue(price,quantity,avgValue);     printTable(Varraysize, vitamin, Parraysize, price, Qarraysize, quantity, totalvalue);     cout<< endl;         // Outputs the average price and final inventory of the arrays.     cout << endl;     cout << "The average price for a vitamin is: \$" << avgValue << endl;     //cout << "The total store inventory is: " << return 0; } // Functions! void getInput(string varray[], string vitamin, double parray[], double price, int qarray[], int quantity) {     int i;     for ( i = 0; i < 3; i++)     {     cout <<"Enter the vitamin name: " <<endl;     cin >> vitamin;     vitamin = varray[i];     cout << endl;     cout << "Enter the price of the vitamins: " << endl;     cin >> price;     price = parray[i];     cout << endl;     cout << "Enter the quantity of vitamins you wish to purchase: " << endl;     cin >> quantity;     quantity = qarray[i];     cout << endl;     } } void totalValue(double price, int quantity, double totalvalue) {     totalvalue = price*quantity;     //cout <<"The total value of your vitamins is: "<<totalvalue<<endl;     cout << endl; } void averageValue(double price, int quanity, double avgValue) {     avgValue = price; } void printTable(string varray[], string vitamin, double parray[], double price, int qarray[], int quantity, double totalvalue) {     cout << setw(10) << left << "Vitamin";     cout << setw(10) << left << "Price";     cout << setw(12) << left << "Inventory";     cout << setw(12) << left << "Total value of inventory \n";     cout << "______________________________________________________________________" << endl;     cout <<setw(10) << left << vitamin;     cout <<setw(10) << left << price;     cout <<setw(12) << left << quantity;     cout <<setw(12) << left << totalvalue; }```
• 12-15-2011
jimblumberg
You may want to check your compiler settings and insure it is generating warnings. Some of the following warnings are probably your problem.
Quote:

main.cpp||In function ‘int main()’:|
main.cpp|25|warning: unused variable ‘size’|
main.cpp|84|warning: unused parameter ‘quanity’|
main.cpp|90|warning: unused parameter ‘varray’|
main.cpp|90|warning: unused parameter ‘parray’|
main.cpp|90|warning: unused parameter ‘qarray’|
main.cpp||In function ‘int main()’:|
main.cpp|34|warning: ‘price’ may be used uninitialized in this function|
main.cpp|34|warning: ‘quantity’ may be used uninitialized in this function|
main.cpp|35|warning: ‘totalvalue’ may be used uninitialized in this function|
main.cpp|36|warning: ‘avgValue’ may be used uninitialized in this function|
Look closely at your uninitialized variables.

Jim
• 12-16-2011
iGuardian
Is what i've written even remotely close to what I need it to do?

Write a C++ programthat will do the following:

1. Read data from the keyboard in the form
vitamin price quantity
2. Call a function that will return the total value of the store's inventory for that one vitamin product (unit_price* number_of_jars).
1. You will also calculate:
The average price of a vitamin
The total inventory (total number of jars)
1. Print the output so that it is organized as follows:

VitaminPriceInventoryTotal Inventory
--------------------------------------------------

 A 12.95 23 297.85 K 9.99 56 559.44 Z 6.99 25 174.75