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{
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);
#include <iostream>
#include<string>
#include<map>
#include <cstdlib>
usingnamespace 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;
}
}
}