Hi i have a college project that i need finished for next wednesday. Its C++ and im ok with it but finding myself constantly stuck. The problem im having at moment is my program will not read the file. when i coment out readfile(); it will run but not display the info i want it to??? I will paste my code so far if its not clear what im asking for please say and i will try and clarify. Thanks in advance!
Hi thank you for replying! Code tags?? Do u mean coments??
Anyways i have a txt file containing data regarding coffee withing this is bean_type purchase_date stock_amount
when i comment out the readfile(); in the main method it will display the menus and i can swap between etc but the program will not read the txt file and display the data??
No, code tags are these: [code] and [/code]. Put your code between them.
when i comment out the readfile(); in the main method it will display the menus and i can swap between etc but the program will not read the txt file and display the data??
Well, obviously. When you comment something out, it will no longer be executed.
Try ifstream infile ("M:\\coffee.txt", ios_base::in ); in your "Readfile()" function. Also you don't declare your cl global variable as an array but you try to use it as such in it looks like all of your functions, fix that. I see what you did there, but when you call date() you don't need to redeclare the data type like you do in readfile(). At this point your abuse of global variables, lack of code tags and having to scroll up and down constantly has caused me to lose interest.
What's the format of your input file? From looking at your Readfile() function, I created a file called 'coffee.txt' like this:
Ground 5 20/04/2003
Fine 3 12/4/2009
Dark 20 1/2/2008
With a basic test, your code seems to work without crashing with this file. After it reads the file, I can use the manager menu to display the inventory. See if you can get that working. If your input format is different, perhaps post it.
As the others have pointed out, the code is far from perfect. I'll throw my two cents in too: there are a bunch of local variables that are unreferenced (at least at this stage of your development)...
'password', 'bean_pos', 'portions', 'num_cups', 'total_portions', 'amount'