How to change values of an array? then display?

how can i change the array value and display the updated value. for example this is the output beginning of the program

-----------------------------------------------------
Part Description Number of parts in the bin
----------------------------------------------------

valve 10
Bearing 5
Bushing 21
Coupling 7
Flange 5
Gear 5
Gear House 5
Vacuum Gripper 25
Cable 18
Rod 12

Here are 3 options
Type A , to Add parts
Type R , to Remove parts
Type E, to Exit Program
Choose your option: a

You will now add
Which part?
How much do you want to add?
Press any key to continue . . .

how can the user input for example "Cable" and then input to add two more, and then display the updated list? Heres my code, and i also need to pass it through a function. Thanks in advance!


#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;
//define Structure as invParts
struct invParts{

string name;
int qty;


};


//void addparts(invParts *&c, int);
//void removeparts(invParts *&, int);




int main()
{
invParts bin[10]= { {"valve",10}, {"Bearing",5}, {"Bushing",21},
{"Coupling",7}, {"Flange",5}, {"Gear",5},
{"Gear House", 5}, {"Vacuum Gripper", 25},
{"Cable",18}, {"Rod",12}, };
invParts *descrip;
int row = 0;
int col = 0;
int num;
double add;
double rem;
char choice;



cout<<"-----------------------------------------------------" << endl;
cout<<"Part Description" << " " << "Number of parts in the bin" << endl;
cout <<"----------------------------------------------------" << endl;
cout << endl;
for(row = 0; row < 10; row++)
{
cout << setw(11)<< left <<bin[row].name << setw(25) << right << bin[row].qty<< endl;



}
cout << endl;
cout << "Here are 3 options" << endl;
cout << "Type A , to Add parts" << endl;
cout << "Type R , to Remove parts" << endl;
cout << "Type E, to Exit Program" << endl;
cout << "Choose your option: ";
cin >> choice;
cout << endl;
switch (choice)
{
case 'A' :
case 'a' : cout <<"You will now add" << endl;
cout <<"Which part? " << endl;
cout <<"How much do you want to add? "<<endl;
//addparts(descrip, num);
break;

case 'R':
case 'r': cout <<"You will now remove" << endl;
cout <<"Which part? ";
cout <<"How much do you want to remove? ";
// removeparts(descrip,num);

break;
case 'E':
case 'e': cout<<"Now exiting program" << endl;
exit(0);




}






system("pause");
return 0;
}




/*void addparts(invParts *&c,int num)
{













}
void removeparts(invParts *&c, int number)
{




}
*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include<string>
#include<map>
#include <cstdlib>

using namespace std;
void addpart();
void show();
void removepart();

map<string,int> tab;
int main()
{
   char ch;

   tab["valve"]= 10;
   tab["Bearing"]= 5;
   tab["Bushing"]= 21;
   tab["Coupling"]= 7;
   tab["Flange"]= 5;
   tab["Gear"]= 5;
   tab["Gear House"]= 5;
   tab["Vacuum Gripper"]= 25;
   tab["Cable"]= 18;
   tab["Rod"]= 12;
show();
   cout<<"A for add, R for remove and E for exit ";
   cin>>ch;

   switch(ch){

   case 'a':
   case  'A':  addpart(); break;
   case 'r':
   case 'R':  removepart(); break;
   case 'e':
   case 'E':  exit(0); break;

   }
cout<<endl<<"current table"<<endl;
show();
  return 0;
}

void addpart(){
    char ans;
    int n;
    cout<<"if you want to add the item type ( y ) else ( n ) against the item and enter"<<endl;
    for(auto it=tab.begin();it!=tab.end();++it){
    cout<<it->first;
    cin>>ans;
    if(ans=='y' or ans=='Y'){
        cout<<"How much do you want to add? ";
        cin>>n;
        it->second+=n;
    return;
    }

    }

}

void show(){

for(auto it=tab.begin();it!=tab.end();++it){
    cout<<it->first<<"-"<<it->second<<endl;

}
}

void removepart(){
    char ans;
    int n;
    cout<<"if you want to remove the item type y else n against the item and enter"<<endl;
    for(auto it=tab.begin();it!=tab.end();++it){
    cout<<it->first;
    cin>>ans;
    if(ans=='y' or ans=='Y'){
        cout<<"How much do you want to remove? ";
        cin>>n;
        it->second-=n;
        return;
    }

    }

}
Topic archived. No new replies allowed.