Hi. My name is Jason. I am very inexperience with c++ programming but have decided to built myself an money tracking application which consists of storing data and read data from a text file. The data are as follows, the date, the product name and the price. Data flows are as follows: Input Date -> Input first item -> input first price ... -> input last item -> input last price. For different date, I can have different quantities of products purchased, meaning the data store is irregular. The price is a double type and is use to calculate total expenses and is unable to use the .getline() function. I have done my school assignment which consists of regular string data store and that was easy but this made me think. I hope that you wont found this silly because I really can't find anything relevant online. Feel free to give me criticism, advise and guidance. Thank you. Here is part of my attempt:
The price is a double type and is use to calculate total expenses and is unable to use the .getline() function.
getline only works with strings. You can either use getline to read the input into a string and then use something like std::ostringstream or std::stod to convert it to a double, or you can use the >> operator which seems like you're already doing.
It's always good to post the whole code - unless it's very long.
I tried to complete it based on your input and came up with this - correct me if I am wrong.
Changed your read code as well. Try and see if it works.
Some remarks:
It would be better if you were consistent with your naming conventions. Why DATE and product?
Better would be Date and Product or date and product.
By convention all uppercase is used for constants.
Never ever use eof for streams. They work not as people expect - Google will tell you the details.
Sorry for the mess guys, this is my first time using this forum.
Thanks Peter87 and Thomas1965 for your help, I will bear in mind with everything I learnt here especially the remarks. The case is closed. Thank you guys for your help