美文网首页
70 - Reviewing the Final Program

70 - Reviewing the Final Program

作者: 社交帐号直接注册 | 来源:发表于2018-01-10 15:01 被阅读0次
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int getwhattheywant();
    void displayitem(int x);
    
    //main function
    int main()
    {
        int whattheywant;
        whattheywant = getwhattheywant();
        while(whattheywant != 4)
        {
            switch(whattheywant)
            {
            case 1:
                displayitem(1);
                break;
            case 2:
                displayitem(2);
                break;
            case 3:
                displayitem(3);
                break;
            }
            whattheywant = getwhattheywant();
        }
    }
    
    //getwhattheywant function
    int getwhattheywant()
    {
        int choice;
        cout << endl << "1 - just plain items" << endl;
        cout << "2 - helpful items" << endl;
        cout << "3 - harmful items" << endl;
        cout << "4 - quit items" << endl;
    
        cin >> choice;
        return choice;
    }
    
    //dispaly items fuunction
    void displayitem(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;
                }
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:70 - Reviewing the Final Program

          本文链接:https://www.haomeiwen.com/subject/hseonxtx.html