Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <iomanip>
- #include <string>
- using namespace std;
- class item
- {
- public:
- item();
- string name;
- double price;
- double profit;
- };
- item::item()
- {
- name = " ";
- price = 0;
- profit = 0;
- }
- int main()
- {
- item a[50];
- string b;
- string c;
- string d;
- string dump;
- ifstream x;
- cout << "What file to load?" << endl;
- cin >> dump;
- x.open(dump.c_str());
- for(int i=0; i<50; i++)
- {
- x >> b;
- if(b.substr(0, 1) == "I")
- {
- x >> a[i].name >> a[i].price;
- }
- if(b.substr(0, 1) == "R") //recipe
- {
- x >> c;
- if(x.eof())
- {
- break;
- }
- for(int j=0; j<50; j++) //connects first string c with a[].name (creation)
- {
- if(c == a[j].name)
- {
- do
- {
- x >> dump;
- if(dump == ";")
- {
- break;
- }
- x >> d;
- for(int k=0; k<50; k++) //connects the = + strings with a[].name (recipe ingredient) and adds their price to the first one's profit
- {
- if(d == a[k].name)
- {
- a[j].profit += a[k].price;
- }
- }
- }while(!(dump == ";"));
- }
- }
- }
- }
- for(int i=0; i<50; i++)
- {
- if(!(a[i].profit == 0))
- {
- a[i].profit = a[i].price - a[i].profit;
- }
- if(a[i].name == " ")
- {
- break;
- }
- cout << "Making " << a[i].name << ", profit=" << a[i].profit << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement