70 - Reviewing the Final Program

#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;
            }
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容