Hello kmcfall,
Sorry for the delay. I saw the post in the other message just as I went to bed.
Looking at the program you start with:
1 2 3 4 5 6 7
|
string VIN, make, model, type, year;
string truck = "TRUCK"; // <--- Should be defined as a constant.
double basefee, weight;
double tax = 0.065; // <--- Should be defined as a constant.
double highwayfund = 2.0; // <--- Should be defined as a constant.
int age;
double discount;
|
Why did you make year a string? "year" is a number and should be an "int".
I would suggest this:
1 2 3 4 5 6 7 8 9
|
constexpr double TAX = 0.065;
constexpr double HIGHWAY_FUND = 2.0;
const string TRUCK = "TRUCK"; // <--- Defined, but never used.
int year{}, weight{};
string vin, make, model, type;
double basefee{};
int age{};
double discount{};
|
In line 6 using "VIN" gives the impression that it is a constant variable that can not be changed. It is a bit misleading, but OK if you want to leave it that way.
As I have said before you define the file streams and open the files, but how do you know that they are open and ready to use?
The while loop will not work the way you are think it will.
Line 24 reads the file, but is doing it wrong. How you set up the variables to read the fields in the file needs to match the way the file is laid out.
Line 25 is trying to read a field in the file that only exists if the "type" is a TRUCK. So this line is trying to read a weight, but the file pointer is at the beginning of the next line ready to read the next vin number, which starts with a letter, causing the stream to fail because it is expecting a number.
Given the line:
age = (2020 - year);
and as
whitenite1 has pointed out you are trying to subtract a string from a number and this does not work. You would have to use
age = (2020 - std::stoi(year));
to make this work. Or just make year an "int" to start with.
Line 27 should not be there. If a weight read from the file is above 12000 to qualify for the 22% additional charge then setting the weight to 12000 would eliminate this charge.
All the if statements need some work.
I do like this:
basefee = (100 - ((100.0 * TAX) - (100 * discount)) + HIGHWAY_FUND);
. Start with a base fee and then subtract the tax. Should you not add the tax before subtracting the discount.
NOTE: you only read the weight if the "type" is "TRUCK", hint hint nudge nudge.
The first thing you need to work on is getting the program to read the file properly. Until then the rest of the program is pointless because yo will not have the correct information to work with.
Writing as with debugging should be done in steps not all at once.
Andy