thanks for reading this question.
Basically I am trying to do a code that can achieve the following:
User will be shown a list of details like this
Terminal View:
Please select the department you want to add participant:
1. Admin
2. HR
3. Normal
4. Back to Main Menu
Selection: 3
normal's Department
UserID: 85 [ Name: Andrew, Department: normal ]
UserID: 86 [ Name: Jacky, Department: normal ]
UserID: 90 [ Name: Baoky, Department: normal ]
Current Selected Participant :
Usage:
Type exit to return to main menu
Type remove userid to remove participant
Type add userid to add participant
Selection:
Question is :
I want to be able to like let user add as many participant as he want until he decide to ‘exit’ to main menu, but how do i store it in a string participant.
How do I detect user input is ‘remove userid’
or ‘add userid’ and then get the userid
e.g add 86
then he add 90
then he decided to remove 90
how do the string keep up with it
Below is my code:
do
{
cout << "Current Selected Participant : " << participant << endl;
cout << "" << endl;
do
{
if(counter>0)
{
//so it wont print twice
cout << "Usage: " << endl;
cout << "Type exit to return to main menu" << endl;
cout << "Type remove userid to remove participant" << endl;
cout << "Type add userid to add participant" << endl;
cout << "" << endl;
cout << "Selection: ";
}
getline(cin,buffer);
counter++;
}while(buffer=="");
if(buffer.find("remove"))
{
str2 = "remove ";
buffer.replace(buffer.find(str2),str2.length(),"");
if(participant.find(buffer))
{
//see if buffer is in participant list
buffer = buffer + ",";
participant.replace(participant.find(buffer),buffer.length(),"");
}
else
{
cout << "There no participant " << buffer << " in the list " << endl;
}
}//buffer find remove keyword
if(buffer=="exit")
{
done=true;
}
else
{
sendToServer = "check_account#"+buffer;
write (clientFd, sendToServer.c_str(), strlen (sendToServer.c_str()) + 1);
//see if server return found or not found
readFromServer = readServer (clientFd);
if(readFromServer=="found")
{
//add to participant list
participant += buffer;
participant += ",";
}
}//end if not exit
}while(done!=true);
Some users suggest i store in a string set, how do i store in a string set, and how do i make terminal able recognize keyword like ‘remove’ and ‘add’ in the selection
then get the user id which is seperate by a whitespace.
Next is how to remove if i store in a string set and how to push new value in.
Don’t store it in a string. Store it in a collection that allows easy insertion and removal, like a
std::set<int>. When the process has finished you can convert the set to whichever representation you feel you need.Here’s a very simple example (not checked to see if it compiles and runs; that’s left as an exercise for the reader!)