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}, };
int row = 0;
int col = 0;
choice input;
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 Add , to Add parts" << endl;
cout << "Type Remove , to Remove parts" << endl;
cout << "Type Exit , to Exit Program" << endl;
cout << "Choose your option ";
cin >> input;
cout << endl;
// right here i want to the user to enter add, remove or exit then want
to have the program to go accordingly. for example if they type add, i want to call the add function, if they type remove i want to call the remove function. and i need to use enum for this project.
i have tried, but does work. i need some help, please and thank you in advance
if(choice = 'add')
cout <<"Add parts" << endl;
//call addparts function here
else if(choice = 'remove')
cout <<"Remove parts" << endl;
// call remove parts function here
else
cout <<"exiting program" <<
//have program exit
system("pause");
return 0;
}
//i comment out these function because i want to make sure the program above goes accordingly.
Enums are defined to represent integers. They don't work like you think.
In your example, Add=0, Remove=1, Exit=2.
When you compile the code it literally replaces Add/Remove/Exit with 0, 1, and 2.
choice input;
I'm not going to explain why this is wrong on so many levels for what you're trying to do, because I don't think you'd understand it.
Basically though, you're trying to get string input from the user. Just do string input;
Remove your enumerator declaration, because you're not even using your enums.
Also, your if statements are wrong for multiple reasons.
I'll just go over the first one and you can figure out the others. if (choice = 'add')
Three problems with your original code.
1. You use ' ' when talking about a specific character. Ex: 'a', 'b'. When talking about a string, you need to use double quotes "Add" or "add"
2. Even if you used quotation marks in this if statement, you still aren't checking if choice is equal to "add". When you use =, you are setting choice to add. When you use ==, you are checking if input is equal to add. So you should be saying if (input=="add")
3. The last two reasons this was wrong was because you should've been checking if (input=="add") since choice isn't even a declared variable, and this was also wrong because you were comparing an enum to a string. By changing choice input; to string input;, you will be checking the correct datatype.
Try making these changes, and if you're still having trouble upload your modified code and we'll see what's wrong with it.
Thanks! Upong re-reading the book and what you said, it totally makes sense!!! I was really misunderstanding enums then, but thankx for the clear up! I got it to work!