I have written some code that would read from a .txt file and display whatever is in that file as output in the program. I don't know why it isn't working. I don't see any errors in the code. I also debugged the program, and all the values for the variables are correct. I am using Eclipse Luna for the IDE with the g++ compiler. When the program is running and prompts me for a number 1-3, when I type in 1 2 or 3 it doesn't do anything and I don't know why. Any insight would be appreciated. Thanks!
#include <iostream>
#include <fstream>
using namespace std;
//function prototypes
int getWhatTheyWant();
void displayItems(int x);
//getWhatTheyWant function
int getWhatTheyWant(){
int choice;
cout << "\n 1 - just plain items" << endl;
cout << "2 - helpful items" << endl;
cout << "3 - harmful items" << endl;
cout << "4 - quit program \n" << endl;
cin >> choice;
return choice;
}
//displayItems function
void displayItems(int x){
ifstream objectFile("objects.txt");
string name;
double power;
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;
}
}
}
}
}
}
}
//main function
int main(){
int whatTheyWant;
whatTheyWant = getWhatTheyWant();
while(whatTheyWant != 4){
switch(whatTheyWant){
case 1:
displayItems(1);
break;
case 2:
displayItems(2);
break;
case 3:
displayItems(3);
break;
}
}
}