473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Adding item and updating 'bins' array.

I am rather new to programming and am coming across a problem with my current program. The program shows bins full of parts. It shows the name of the bin and then how many parts are in the bin. The program then asks for the user to update the data in the bins. The problem I cannot figure out is how to update the data in the array of bins. For instance, the program runs, I choose to add 5 parts to the Valve bin, how do I make th valve bin show this change when the program loops back again? I have made a couple attempts only to find that I have no idea right now. I'll appreciate any guidance and help you can give. Thanks!

Expand|Select|Wrap|Line Numbers
  1. ..const int LENGTH = 20;
  2.  
  3. struct Data
  4. {
  5.   char description[LENGTH];
  6.   int number;
  7.  
  8. };
  9.  
  10. int main()
  11. {
  12.   Data part;
  13.   int choice;
  14.   int b;
  15.   int add=0;
  16.   int remove=0;
  17.   Data bins[10] = {
  18.                         {"Valve",10},
  19.                         {"Bearing",5},
  20.                         {"Bushing",15},
  21.                         {"Coupling",21},
  22.                         {"Flange",7},
  23.                         {"Gear",5},
  24.                         {"Gear Housing",5},
  25.                         {"Vacuum Gripper",25},
  26.                         {"Cable",18},
  27.                         {"Rod",12}
  28.                         };
  29. for( ; ; )
  30. {
  31.  cout<<endl;
  32. for (int index = 0; index < 10; index++)
  33.   {
  34.    cout<< right << setw(8)<< "Part Description: " << bins[index].description;
  35.    cout<< right << setw(8)<< "     Number of parts in bin: " << bins[index].number <<endl;
  36.  
  37.   }
  38.   cout << "\n\t\tPROGRAM MENU\n\n";
  39.   cout << "0. Valve\n";
  40.   cout << "1. Bearing\n";
  41.   cout << "2. Bushing\n";
  42.   cout << "3. Coupling\n";
  43.   cout << "4. Flange\n";
  44.   cout << "5. Gear\n";
  45.   cout << "6. Gear Housing\n";
  46.   cout << "7. Vacuum Gripper\n";
  47.   cout << "8. Cable\n";
  48.   cout << "9. Rod\n";
  49.   cout <<endl;
  50.   cout << "Enter choice from the Menu to select a bin: ";
  51.   cin >> choice;
  52.  
  53.    cout << "\nYou have selected the " << bins[choice].description << " bin with " << bins[choice].number << " parts in it." <<endl;
  54.    cout << "\nWould you like to add parts or remove parts? \nEnter number choice from menu please.\n";
  55.    cout << "\n\t\tADD/REMOVE MENU\n\n";
  56.    cout << "1. ADD PARTS TO A BIN\n";
  57.    cout << "2. REMOVE PARTS FROM A BIN\n";
  58.    cout <<endl;
  59.    cin >> b;
  60.    if (b == 1)
  61.    {
  62.     cout << "\nType the number of parts you would like to add to the bin: ";
  63.     cin >> add;
  64.     while ( add + bins[choice].number > 30)
  65.     {
  66.     cout << "\nThe number is too great. The bin can hold no more than 30 parts.";
  67.     cout << "\nPlease try a different number: ";
  68.     cin >> add;
  69.  
  70.     }
  71.  
  72.     }
  73.  
  74.    else if(b == 2)
  75.    {
  76.  
  77.  
  78.    cout << "\nType the number of parts you would like to remove from the bin: ";
  79.    cin >> remove;
  80.    while (remove < 0)
  81.    {
  82.    cout << "\nPlease enter a positive number only: ";
  83.    cin >> remove;
  84.    }
  85.  
  86.    }
  87.   }
  88.  getch();
  89. }..
Nov 30 '07 #1
1 2303
sicarie
4,677 Expert Mod 4TB
Aside of your lack of headers, your for loop that should be a while and has no exit, I don't see, logically, where you try to add something to the bins - you just check to see if it's over 30 when added to another element. Am I just missing that, or can you post that specific part of the code you're having trouble with?
Nov 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: David | last post by:
I have an array that contains numbers in string elements , i want to convert this to integers, i have made a for loop that uses the number of elements in the array and then adds 0, thereby...
5
by: R.G. Vervoort | last post by:
Not sure if it is a php question but since i am working in php here it is. Ho can i add items to (the item label=visual text and the value=index number) a list object on a website. I am having...
12
by: MCD | last post by:
Hello, I'm new to python and this group and am trying to build some bins and was wondering if any of you could kindly help me out. I'm a bit lost on how to begin. I have some text files that...
0
by: Stephen | last post by:
I have been getting on well with help from this forum trying to create an array list and work with it. Everything is working fine apart from displaying my array list items into the labels in my...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
14
by: Karl Irvin | last post by:
While adding data to a record set, I use something like rst! = some variable rst! = some variable ...... rst! = some variable The rst! , rst! etc. are manually typed in and it gets...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
10
by: Phat G5 (G3) | last post by:
I was toying around with adding a new method to the Array class. It works fine in FF but not in Safari. I have no idea in IE. I have not gotten that far yet. Array.prototype.find =...
9
by: Kiamari | last post by:
here's what i have to do: Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.