Hello DrCoke21,
I tent to take a different approach to programs. For your code the first thing I would work on is reading the file.
Which by the way you should post the input file so everyone can use the same information when dealing with your program. If it is large at least a fair sample, (5 to 10 lines or records).
My first question is how do you know that the file stream is open and usable?
I use this when dealing with "fstream"s:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int main()
{
double startingBalance{}, checksWrote{};
std::string inFileName{ "transaction.txt" };
std::ifstream inFile(inFileName);
if (!inFile)
{
std::cout << "\n File " << std::quoted(inFileName) << " did not open" << std::endl;
//std::this_thread::sleep_for(std::chrono::seconds(3)); // <--- Needs header files chrono" and "thread". Optional
return 1; //exit(1); // If not in "main".
}
|
Line 3 is there to point out that it is a good idea to initialize your variables. This becomes even more true when you define
double totalFee;
in the while loop.
The reason for line 13 is that you do not want to continue with the program until you fix the problem.
These lines:
1 2 3 4 5
|
int range1, range2, range3, overDrawn; // <--- Would consider making these constant.
range1 = 20,
range2 = 39,
range3 = 59,
overDrawn = 400;
|
Could be written as:
1 2 3 4 5
|
int range1{ 20 }, range2{ 39 }, range3{ 59 }, overDrawn{ 400 }; // <--- Would consider making these constant.
//range1 = 20,
// range2 = 39,
// range3 = 59,
// overDrawn = 400;
|
And these lines:
1 2 3 4 5 6 7
|
const double
TEN_CENTS = .10, // <--- Stored as 0.10000000000000000056
EIGHT_CENTS = .08, // <--- Stored as 0.08000000000000000167
SIX_CENTS = .06, // <--- Stored as 0.05999999999999999778
FOUR_CENTS = .04, // <--- Stored as 0.04000000000000000083
MONTHLYFEE = 10.0,
EXTRAFEE = 15.0;
|
For the last two lines this would be the proper to initialize a "double".
Watch your use of blank lines and indenting. I missed the opening brace of the while loop the first time I looked at your code. It was to far to the left and I was not expecting that.
The while condition is a good start.
Inside the while loop I noticed the use of "overDrawn" is misleading. Something like "MINIMUNBALANCE" or "MINBALANCE" is more descriptive and it should be defined as a constant.
The line
totalFee = (totalFee += EXTRAFEE);
may work, but does not make much sense. I think what you may want here is
totalFee += EXTRAFEE;
.
The if statement on line 52 is looking for its closing }. The closing } on line 56 is actually paired with the if statement on line 54. For now you could put a ';' on line 55 to make it work correctly.
Not that it appears to be a problem, but on line 44 you are comparing a "double" to an "int".
As for what you are doing from line 40 on I have not worked on that part yet until I have some data to work with.
That is a start for now.
Andy