I created three files, Checkout.cpp, grocery.cpp and grocery.h
I try to build it and it creates an exe file but when I run it I dont get the intentory list to tell what I sell. Can someone see what Im doing wrong? thanks
Also, I want to convert this to be able to run on my nova account in UNIX. I know I can put in .cpp files but how can I build everything so it will be able to run without an exe file that C++ creates?
32998 fruity-pebbles 2.99 T
33125 eggs 2.09 T
31002 pancakes 3.59 T
41505 syrup 1.49 T
52458 dryer-sheets 0.99 N
53220 twinkies 1.29 T
63889 bagels 1.49 T
int main ( )
{
Stockroom stockroom(30);
//The following line will only open the file.
//It doesn't actually read and/or display anything from the file
ifstream invent(INVENT); // Read inventory - No it doesn't
ofstream receipts(RECEIPTS);
<SNIP>
Also why in checkout.cpp do you include grocery.cpp?
Yes you can include *.cpp files in other cpp files, but it usually for a special reason, not standard practice.
If I dont include grocery.cpp in my checkout file than it gives all these errors so when I add it they all go away. I thought the Inventroy file was nt reading...do you know of a way to make it read from my .in file which contins my inventory file so it will show on the program to chose from?
If I dont include grocery.cpp in my checkout file than it gives all these errors so when I add it they all go away. That is because your prject is not setup properly - but we will come back to that.
This is what I have done.
checkout.cpp
I have added a function to the stockroom class called void LoadGroceryList(constchar* Filename);.
So now in checkout.cpp Lines 17 and 18 - we make the stockroom variable.
We then call this Stockroom member function with the name of the inventory file - and it loads the grocery data.
See grocery.h line 60 and grocery.cpp line 78 onwards
Thanks for helping me with my code...I knew I wasnt calling to list it but i couldnt figure out why....
When i compile it and build I run the exe file and it still says
Enter purchases for customer 1
Enter profcut code 0 to end purchases
It still wont load my Inventory file up...is my Invent.in the right file to use? or should I be using a cpp file? Maybe this is what Im doing wrong....should I add the Inventory file in with another one some how? thanks
To be honest, I only concentrated on loading the invent.in file.
So using the three files, I have posted should sort that out.
I haven't attempted to find and cure all the other errors (I was leaving that to you).
Line 22 stockroom.WriteStock(cout); // and onto screen - works - so you should see the inventory that was loaded displayed on the screen.
The rest of the code after that, (where you enter customer purchases - I haven't looked at).
Your program is working - to a degree.
here is what appeared on my screen when I tried to buy some bagels for
customer 1:
32998 fruity-pebbles2.99 T
33125 eggs 2.09 T
31002 pancakes 3.59 T
41505 syrup 1.49 T
52458 dryer-sheets 0.99 N
53220 twinkies 1.29 T
63889 bagels 1.49 T
Enter purchases for customer 1
Enter product code 0 to end purchases
63889
6
bagels 6 @ 1.49 8.94 TX
0
Subtotal 8.94
Tax 0.67
Total 9.61
Is there another customer? (Y/N)
here is what appeared in the receipts.out file when I finished
32998 fruity-pebbles2.99 T
33125 eggs 2.09 T
31002 pancakes 3.59 T
41505 syrup 1.49 T
52458 dryer-sheets 0.99 N
53220 twinkies 1.29 T
63889 bagels 1.49 T
I went as far to copy your entire sections that you rewrote and I saved them all and compiled tham and rebuilt them... Im using Visuall C++ 6.0. Should I be using something different to recompile this?
I was just wondering - it was just that it seemed not to be loading up the invent.in file. Because it should load it and display it as per checkout.cpp lines 20 and 22.
That file should be in the same directory as the project - because I believe the VC++ sets the working directory to be the project directory when it runs the program.
Can you use mycomputer/Explorer to find where the invent.in file is located? Is it in the project directory?
This is the problem with forum based diagnostics - if I was there we would have sorted the problem by now.
Perfect!!!! I put the Invent.in file in my debug folder with the exe file and it loaded it all up like it should...everything worked great except when I said there was a new customer after I bought some things it just shut down.but oh well..it is finally doing what it should....thaks alot for helping me...
Glad it's starting to work for you now :-).
I'm aware of the problem you mentioned, it's to do with this check:
1 2 3 4 5 6
cout << "Is there another customer? (Y/N) ";
cin >> more;
} while (more == "Y"); //PROBLEM HERE
if (more == "N") //By the way this line is basically redundatnt.
cout << "Thanks for shopping at Bryan's Market." << endl;
The problem being that more will only be Y if the user uses the CAPS or SHIFT key to enter the letter y - otherewise it will be y.
I suggest you change more to be a char rather than a string and you need to check for either Y or y
So you will have this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//other stuff as before
int customer = 1; //First Cusromer
char more; //more is now type char
//other stuff as before
cout << "Is there another customer? (Y/N) ";
cin >> more;
} while (more == 'Y' || more == 'y'); //check for Y or y. Notice also the SINGLE quotes
//The line if (more == "N") has now been removed
cout << "Thanks for shopping at Bryan's Market." << endl;
//other stuff as before