Like Tree1Likes
  • 1 Post By jimblumberg

Basic Array question

This is a discussion on Basic Array question within the C++ Programming forums, part of the General Programming Boards category; For some reason when I run the program I output hexidecimals. Can anyone help me with this and point me ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    30

    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;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,758
    You may want to check your compiler settings and insure it is generating warnings. Some of the following warnings are probably your problem.
    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
    iMalc likes this.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    30
    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
    Last edited by iGuardian; 12-15-2011 at 11:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic array help
    By shouse in forum C Programming
    Replies: 5
    Last Post: 04-03-2011, 08:58 PM
  2. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  3. Basic array question(s)
    By cnewbie1 in forum C Programming
    Replies: 18
    Last Post: 11-06-2010, 02:25 PM
  4. Basic question on character array
    By vandrea in forum C Programming
    Replies: 6
    Last Post: 09-20-2009, 12:05 AM
  5. Basic Array help
    By diddy02 in forum C Programming
    Replies: 21
    Last Post: 08-03-2002, 02:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21