Thanks for the update....
Ok so the problem is as I expect ... To make the problem skip over you need some kind of conditional statement to skip over the output operations. Right now you have:
1 2 3 4 5 6 7 8 9
|
input_data (fin, full_name, taxID, grossINCOME);
while (!fin.eof())
{
taxedAMOUNT = taxes(grossINCOME);
netINCOME = net_income(grossINCOME, taxedAMOUNT);
print_data (fout, full_name, taxID, grossINCOME, taxedAMOUNT, netINCOME);
input_data (fin, full_name, taxID, grossINCOME);
}
|
What you need is something like:
1 2 3 4 5 6 7 8 9 10 11
|
input_data (fin, full_name, taxID, grossINCOME);
while (!fin.eof())
{
if( this is a valid entry ) // <--- this is what you need
{
taxedAMOUNT = taxes(grossINCOME);
netINCOME = net_income(grossINCOME, taxedAMOUNT);
print_data (fout, full_name, taxID, grossINCOME, taxedAMOUNT, netINCOME);
}
input_data (fin, full_name, taxID, grossINCOME);
}
|
I will leave it up to you to figure out what to put in the if statement.... now what you have in the input_data function is close but it only tests the tax_id you need to add the income consideration....:
if (!(tax_id >= 1000 && tax_id <= 9999))
The solution I think you are trying to get working:
-----------------------------------------------------------------
I suspect you are wondering why this if statement in the input data function does not skip over the data? the reason is you are testing inside one function but the output operation you want to skip over is outside that function. If you wanted the input function to perform the test, then you need to have that input function to tell the caller the result of that test (i.e. was the input is invalid?). Currently you have it returning void, you could change it to return true or false depending on whether the conditions are met. Then in the calling code you can save the result and use it in the if statement I added.
Now this is not really a good solution. In programming you should try to write functions that serves only one purpose. This way you can use the same code for other projects. This validity check is a separate purpose than simply reading a file. By putting it in the input function you can only use that input function in this program and no where else.
Improved solution:
-------------------------
Make the input program do input and only input. No testing nothing. Then based on the results of the input function, test whether the conditions are true just before the if statement I inserted for you. Now you could put the test logic (e.g. tax_id >= 1000 && tax_id <= 9999 && income>0 ) directly in the if statement but there is a better solution.
The test logic is something that you might want to place in a separate function that returns a bool. A separate function has benefits for code maintenance. lets say the gov changes the range of valid tax id's. Then you only need to change that one function. If you put that condition directly in the larger program, then you have to search the code and find all those times you performed the test. Also a separate function always means you can use the code for another program.