Hi there, i was trying to make a program (to do)using list class here
is the code
#include<iostream>
using namespace std;
#include<list>
#include<string>
void display(const list<string>& lsy){
list<string>::const_iterator iter = lsy.cbegin();
int i = 0;
while (iter != lsy.end()){
cout <<++i<<"- "<< *iter << endl;
++iter;
}
}
void add(list<string>&ls){
string name;
cout << "Enter the task : ";
getline(cin, name);
ls.push_back(name);
display(ls);
}
int main(){
//cout << "1- add item 2- remove item 3- display items 4- terminate";
bool active = true;
unsigned int command;
list<string>items;
while (active){
cout << "\n> "; cin >> command;
if (command == 1)add(items);//here is the problem !
else if (command == 2);// remove();
else if (command == 3) display(items);
else if (command == 4) active = false;
else
cout << "bad command...try again";
}
system("pause");
return 0;
}
//make a display function
//add items
//remove item
//clean all items(restart)
the add item function works fine individually when i tested it , but when i insert it inside the if statements or using switch
when i choose command==1 to get into the function , the program reaches the cout statement then it returns to main as it didn't see the rest of the code :/ ,test it please and what's the problem and how to fix it?!