Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,008 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,387 people online right now. Registration is fast and FREE... Join Now!




Inventory using arrays

 
Reply to this topicStart new topic

Inventory using arrays

livefromyadkin
28 Nov, 2006 - 03:45 PM
Post #1

New D.I.C Head
*

Joined: 22 Sep, 2006
Posts: 24


My Contributions
Hello All,

Here is the assignment...

"Create a program that manages inventory bins in a warehouse. Each bin holds a number of the same type of part. The program should use a structure that keeps the following information: Description of the part kept in the bin, Number of parts in the bin.

Create an array of ten of these structures, whose elements should be initialized with the data on page 564.

The Program should have the following functions as detailed on page 564: DisplayBins(), addParts(),removeParts().

The program should begin by initializing the array with the data for each of the 10 bins (you can allow the end user to put this in). Then it should enter a loop that:

1) calls the displayBins function to display the current bin status

2) Allows the user to choose to either quit the program or select a bin

3) If a bin is selected, allows the user to choose whether to ad parts to it or remove parts from it

4) Have the user input the number of parts to be added or removed

5) Call the appropriate function to add or remove parts

After the user exits the loop, a final call should be made to the displayBins function before ending the program.

<no bin can hold more than 30 parts, do not allow user to remove parts from an empty bin, accept only positive integers (counting numbers) as amounts to add or remove from the bin>"

...and here is my code so far...

CODE

#include <iostream>
#include <iomanip>

using namespace std;


    void showBin (int [], int);


int main()
{

    const int SIZE = 10;
    int array1[SIZE] = {10,5,15,21,7,5,5,25,18,12};
    int count;
    int menu, addremove, add, remove, binnum;





    cout<<"********************************************** \n";
    cout<<"*                    MENU                    * \n";
    cout<<"*                                            * \n";
    cout<<"*               1. Select a Bin              * \n";
    cout<<"*                2. View Bins                * \n";
    cout<<"*                  3. Quit                   * \n";
    cout<<"********************************************** \n";
    cin>>menu;
    switch (menu)
    {
    case 1:
        {
                    cout<<"**************************************** \n";
                    cout<<"* ENTER THE BIN NUMBER YOU WISH TO USE * \n";
                    cout<<"*   1. Valve         2. Bearing        * \n";
                    cout<<"*   3. Bushing       4. Coupling       * \n";
                    cout<<"*   5. Flange        6. Gear           * \n";
                    cout<<"*   7. Gear Housing  8. Vaccum Gripper * \n";
                    cout<<"*   9. Cable        10. Rod            * \n";
                    cout<<"**************************************** \n";
                    cin>>binnum;



            cout<<"******************************* \n";
            cout<<"*        1. Add to bin        * \n";
            cout<<"*     2. Remove from bin      * \n";
            cout<<"******************************* \n";
            cin>>addremove;
            switch(addremove)
            {
            case 1:
                {

                    cout<<"Enter how many parts you wish to add to bin"<< binnum<<". \n";
                    cin>>add;

                    int addedbin = array1[binnum] + add;
                    cout<<"bin "<<binnum<<" now has "<<addedbin<<endl;
                    break;
                }
            case 2:
                {
                    cout<<"Enter how many parts you wish to remove from bin"<< binnum<<". \n";
                    cin>>remove;

                    int rembin = array1[binnum] - remove;
                    cout<<"bin "<<binnum<<" now has "<<rembin<<endl;
                    break;
                }
            break;
            }
        break;
        }
                    


    case 2:
        {

            showBin (array1, SIZE);

            break;
        }
    case 3:
        {        
        cout<<"Thanks for using Inventory. Come back soon!!! \n";
        break;
        }



return 0;
}

void showBin (int nums[], int SIZE)
{
        for (int count = 0; count < SIZE; count++)
        cout<<nums[count]<<" ";
        cout<<endl;
}


I'm getting 2 errors when compiling this code.

CODE

error C2601: 'showBin' : local function definitions are illegal


and

CODE

fatal error C1004: unexpected end of file found


...can someone help me out?

Thanks!
-Adam
User is offlineProfile CardPM
+Quote Post

Dark_Nexus
RE: Inventory Using Arrays
28 Nov, 2006 - 04:16 PM
Post #2

or something bad...real bad.
Group Icon

Joined: 2 May, 2004
Posts: 1,309



Thanked: 3 times
Dream Kudos: 625
My Contributions
sounds like you've got some mis matched barckets { }

may want to run through and make sure you have the right number of opening and closing brackets.
User is offlineProfile CardPM
+Quote Post

livefromyadkin
RE: Inventory Using Arrays
29 Nov, 2006 - 01:54 PM
Post #3

New D.I.C Head
*

Joined: 22 Sep, 2006
Posts: 24


My Contributions
You were right! I looked over that code 50 times trying to find the error and over looked it. Now, how do I add a specific number (chosen by the user) to an element in the array?

Here is what I have (same code from post#1) and it doesn't seem to work right...

CODE

#include <iostream>
#include <iomanip>

using namespace std;


    void showBin (int [], int);


int main()
{

    const int SIZE = 10;
    int array1[SIZE] = {10,5,15,21,7,5,5,25,18,12};
    
    int menu, addremove, add, remove, binnum;



    do{

    cout<<"********************************************** \n";
    cout<<"*                    MENU                    * \n";
    cout<<"*                                            * \n";
    cout<<"*               1. Select a Bin              * \n";
    cout<<"*                2. View Bins                * \n";
    cout<<"*                  3. Quit                   * \n";
    cout<<"********************************************** \n";
    cin>>menu;
    switch (menu)
    {
    case 1:
        {
                    cout<<"**************************************** \n";
                    cout<<"* ENTER THE BIN NUMBER YOU WISH TO USE * \n";
                    cout<<"*   1. Valve         2. Bearing        * \n";
                    cout<<"*   3. Bushing       4. Coupling       * \n";
                    cout<<"*   5. Flange        6. Gear           * \n";
                    cout<<"*   7. Gear Housing  8. Vaccum Gripper * \n";
                    cout<<"*   9. Cable        10. Rod            * \n";
                    cout<<"**************************************** \n";
                    cin>>binnum;



            cout<<"******************************* \n";
            cout<<"*        1. Add to bin        * \n";
            cout<<"*     2. Remove from bin      * \n";
            cout<<"******************************* \n";
            cin>>addremove;
            switch(addremove)
            {
            case 1:
                {

                    cout<<"Enter how many parts you wish to add to bin"<< binnum<<". \n";
                    cin>>add;

                    int addedbin = array1[binnum] + add;
                    cout<<"bin "<<binnum<<" now has "<<addedbin<<endl;
                    break;
                }
            case 2:
                {
                    cout<<"Enter how many parts you wish to remove from bin"<< binnum<<". \n";
                    cin>>remove;

                    int rembin = array1[binnum] - remove;
                    cout<<"bin "<<binnum<<" now has "<<rembin<<endl;
                    break;
                }
            break;
            }
        break;
        }
                    


    case 2:
        {

            showBin (array1, SIZE);

            break;
        }
    case 3:
        {        
        cout<<"Thanks for using Inventory. Come back soon!!! \n";
        break;
        }
        
    break;
    }

    }
    while (menu != 3);

return 0;
}

void showBin (int nums[], int SIZE)
{
        for (int count = 0; count < SIZE; count++)
        cout<<nums[count]<<" ";
        cout<<endl;
}


How can I make this part work correctly?
CODE


    int addedbin = array1[binnum] + add;
        cout<<"bin "<<binnum<<" now has "<<addedbin<<endl;

User is offlineProfile CardPM
+Quote Post

BitByte
RE: Inventory Using Arrays
29 Nov, 2006 - 02:04 PM
Post #4

D.I.C Head
**

Joined: 9 Aug, 2006
Posts: 194



Thanked: 3 times
My Contributions
Just use:

CODE
array[elem] += number;


This post has been edited by BitByte: 29 Nov, 2006 - 02:04 PM
User is offlineProfile CardPM
+Quote Post

Dark_Nexus
RE: Inventory Using Arrays
29 Nov, 2006 - 02:09 PM
Post #5

or something bad...real bad.
Group Icon

Joined: 2 May, 2004
Posts: 1,309



Thanked: 3 times
Dream Kudos: 625
My Contributions
also, be sure to remember when you are accessing elements in an array, the indexes are in an n-1 format.

for example:

accessing element 5...
array[4];

accessing element 9...
array[8];

and so on
User is offlineProfile CardPM
+Quote Post

livefromyadkin
RE: Inventory Using Arrays
29 Nov, 2006 - 02:20 PM
Post #6

New D.I.C Head
*

Joined: 22 Sep, 2006
Posts: 24


My Contributions
o shot, I forgot element 0. I'm such a noob! Sorry guys...Thanks for your help!
User is offlineProfile CardPM
+Quote Post

Xing
RE: Inventory Using Arrays
29 Nov, 2006 - 05:30 PM
Post #7

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 4 times
Dream Kudos: 1575
My Contributions
QUOTE(livefromyadkin @ 30 Nov, 2006 - 03:50 AM) *

o shot, I forgot element 0. I'm such a noob! Sorry guys...Thanks for your help!


It's actually n00b biggrin.gif....You can ignore this...

This post has been edited by Xing: 29 Nov, 2006 - 05:31 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 08:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month