Hello this program is supposed to take input from a user for a desired car (model, maximum mileage and maximum price) and compare it with all the cars in the data file to tell the user how many cars match their description. So far, this program I have below works as far as I can tell. However, I need to change it to include two functions: one is get_next_car (to cycle through cars) and then next is compare_cars (to compare each inventory car to the user's car. I do not know how to do this, can someone please show me how I would include those? Thank you.
As some general first steps, I think you're going to need an array of your car structs, so that you may cycle through the cars.
As for the comparison, it's a bit vague. What are you looking to compare? Are you actually checking the differences between elements (say mileage) functionally, or are you just looking to display the stats from each car on the screen?
Use a vector, not an array. You could have data files that hold different quantities of car makes/models, and an array might cause you to have an exception, since you can't dynamically allocate space for it.
Also, be more specific about what you want to have happen.
I just need to make two functions...I was told they could be boolean expressions. The get_next_car needs to tell the program to read the next line of data and then compare_car would read that line (model, mileage, price) and compare it to the user's input to see if it fits. Could you show me how I would do this please?
Step 1 : use vector to store the data from the file .
Step 2 : iterate the vector to get the number matching your decription of your care .
Step 3 : simultanously store the postion of the vector that matching your description in the int array .
Step 5: just interate to the position you have stored in the int array on the choice in the function show next .