Guest User

b

a guest
May 20th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int getWhatTheyWant();
  6. void displayItems(int x);
  7.  
  8. //main function
  9. int main(){
  10.  
  11.     int whatTheyWant;
  12.  
  13.     whatTheyWant = getWhatTheyWant();
  14.  
  15.     while(whatTheyWant !=4){
  16.         switch(whatTheyWant){
  17.             case 1:
  18.                 displayItems (1);
  19.                 break;
  20.             case 2:
  21.                 displayItems (2);
  22.                 break;
  23.             case 3:
  24.                 displayItems (3);
  25.                 break;
  26.  
  27.  
  28.         }
  29.         whatTheyWant = getWhatTheyWant();
  30.     }
  31.  
  32. }
  33.  
  34. //getWhatTheyWant funcion
  35. int getWhatTheyWant(){
  36.     int choice;
  37.  
  38.     cout << "\n1 - just plain items" << endl;
  39.     cout << "2 - helpful items" << endl;
  40.     cout << "3 - harmful items" << endl;
  41.     cout << "4 - quit program\n" << endl;
  42.  
  43.  
  44.     cin >> choice;
  45.     return choice;
  46. }
  47.  
  48. //display items function
  49. void displayItems(int x){
  50.  
  51.     ifstream objectFile("objects.txt");
  52.     string name;
  53.     double power;
  54.  
  55.     if(x==1){
  56.         while(objectFile >> name >> power){
  57.             if(power==0){
  58.                 cout << name << ' ' << power << endl;
  59.             }
  60.         }
  61.     }
  62.  
  63.     if(x==2){
  64.         while(objectFile >> name >> power){
  65.             if(power>0){
  66.                 cout << name << ' ' << power << endl;
  67.             }
  68.         }
  69.     }
  70.  
  71.     if(x==3){
  72.         while(objectFile >> name >> power){
  73.             if(power<0){
  74.                 cout << name << ' ' << power << endl;
  75.             }
  76.         }
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment