stuck in infinite loop, not running other function
I don not know why my code, do not run as i have wrote it? please help me by coping this program on your code block and help me to resolve the problem, thanks in advanced. #include <iostream> #include<fstream> #include<string> using namespace std; int getwhattheywant(); void displays(int x); int main() { string name; double power; ofstream objectfile ( "objects.txt") ; cout<< "enter name, power"<<endl; cout<<"enter ctrl+z to quit"<<endl; while(cin>> name>>power){ objectfile<<name<<" "<<power<<endl; } int whattheywant; whattheywant = getwhattheywant(); while(whattheywant!=4){ switch(whattheywant){ case1: displays(1); break; case2: displays(2); break; case3: displays(3); break; } whattheywant = getwhattheywant(); } } int getwhattheywant(){ int choice; cout<< "1-just plain items"<<endl; cout<<"2-helpful"<<endl; cout<<"3-harmful"<<endl; cout<<"4-quit"<<endl; cin>> choice; return choice; } void displays(int x) { ifstream objectfile("objects.txt"); double power; string name; if (x==1){ while(objectfile>>name>>power){ if(power==0){ cout<< name << " "<< power<<endl; } } } if (x==2){ while(objectfile>>name>>power){ if(power>0){ cout<< name << " "<< power<<endl; } } } if (x==3){ while(objectfile>>name>>power){ if(power<0){ cout<< name << " "<< power<<endl; } } } }