Homework Solution: Need help. I don't know why the last line of output always read twice…

    Need help. I don't know why the last line of output always read twice #include<iostream> /*Header file for input and output stream (cin, and cout)*/ #include<fstream> /*Header file for file input stream and file output stream*/ using namespace std; int main() /*main() function definition starts here*/ { ifstream in; /*in is an object for ifstream class, ifstream is for input file stream*/ in.open("C:\Users\cartoon1961\Desktop\transaction.txt");/*opening the file "transaction.txt" in read mode*/ float balance, bankfee;/*variable declaration*/ int checks;/*variable declaration*/ while (!in.eof())/*while it is not the end-of-the file, loop repeats*/ { in >> balance;/*reading balance from the file into variable called 'balance'*/ in >> checks;/*reading checks from the file into variable called 'checks'*/ if (balance<0)/* if the balance is less than zero, enters into body of if */ { if (checks<20 && checks >= 0) /*if checks are more than or equal to zero and less than 20*/ { bankfee = 10 + (0.1*checks) + 15; /*claculates the bankfee*/ } else if (checks >= 20 && checks<40)/*if checks are more than or equal to 20 and less than 40*/ { bankfee = 10 + (0.08*checks) + 15;/*claculates the bankfee*/ } else if (checks >= 40 && checks<60)/*if checks are more than or equal to 40 and less than 60*/ { bankfee = 10 + (0.06*checks) + 15;/*claculates the bankfee*/ } else if (checks >= 60)/*if checks are more than or equal to 60*/ { bankfee = 10 + (0.04*checks) + 15;/*claculates the bankfee*/ } cout << "Beginning balance:$" << balance << endl; /*printing details*/ cout << "Number of checks written:" << checks << endl; cout << "Your account is overdrawn!" << endl; cout << "The bank fee this month is:$" << bankfee << endl << endl; } /*end of if*/ else if (balance<400 && balance >= 0) /*otherwise, if balance is greater than or equal to 0 and less than 400 */ { if (checks<20 && checks >= 0)/*if checks are more than or equal to zero and less than 20*/ { bankfee = 10 + (0.1*checks) + 15;/*claculates the bankfee*/ } else if (checks >= 20 && checks<40)/*if checks are more than or equal to 20 and less than 40*/ { bankfee = 10 + (0.08*checks) + 15;/*claculates the bankfee*/ } else if (checks >= 40 && checks<60)/*if checks are more than or equal to 40 and less than 60*/ { bankfee = 10 + (0.06*checks) + 15;/*claculates the bankfee*/ } else if (checks >= 60)/*if checks are more than or equal to 60*/ { bankfee = 10 + (0.04*checks) + 15;/*claculates the bankfee*/ } cout << "Beginning balance:$" << balance << endl;/*printing details*/ cout << "Number of checks written:" << checks << endl; cout << "The bank fee this month is:$" << bankfee << endl << endl; }/*end of else*/ else if (balance >= 400)/*otherwise, if balance greater than or equal to 400*/ { if (checks<0) /*if checks are less than 0*/ { cout << "Beginning balance:$" << balance << endl;/*printing details*/ cout << "Number of checks written:" << checks << endl; cout << "Number of checks must be zero or more." << endl << endl; }/*end of inner if*/ else /*otherwise*/ { if (checks<20 && checks>0)/*if checks are more than or equal to zero and less than 20*/ { bankfee = 10 + (0.1*checks);/*claculates the bankfee*/ } else if (checks >= 20 && checks<40)/*if checks are more than or equal to 20 and less than 40*/ { bankfee = 10 + (0.08*checks);/*claculates the bankfee*/ } else if (checks >= 40 && checks<60)/*if checks are more than or equal to 40 and less than 60*/ { bankfee = 10 + (0.06*checks);/*claculates the bankfee*/ } else if (checks >= 60)/*if checks are more than or equal to 60*/ { bankfee = 10 + (0.04*checks);/*claculates the bankfee*/ } cout << "Beginning balance:$" << balance << endl;/*printing details*/ cout << "Number of checks written:" << checks << endl; cout << "The bank fee this month is:$" << bankfee << endl << endl; }/*end of inner else*/ }/*end of else*/ }/*end of loop*/ return 0; }/*end of main() function*/

    Expert Answer

     
    #include<iostream> /*Header file for input and output stream (cin, and cout)*/ #include<fstream> /*Header file for file input stream and file output stream*/

    Need acceleration. I don’t perceive why the last continuity of output regularly recognize twice

    #include<iostream> /*Header finish control input and output tide (cin, and cout)*/

    #include<fstream> /*Header finish control finish input tide and finish output tide*/

    using namespace std;

    int deep() /*main() part specification starts here*/

    {

    iftide in; /*in is an motive control iftide collocate, iftide is control input finish tide*/

    in.open(“C:\Users\cartoon1961\Desktop\transaction.txt”);/*inauguration the finish “transaction.txt” in recognize order*/

    float adjust, bankfee;/*inconstant statement*/

    int checks;/*inconstant statement*/

    timeliness (!in.eof())/*timeliness it is referable the view-of-the finish, loop repeats*/

    {

    in >> adjust;/*balbutiation adjust from the finish into inconstant designated ‘balance’*/

    in >> checks;/*balbutiation checks from the finish into inconstant designated ‘checks’*/

    if (balance<0)/* if the adjust is close than cipher, enters into mass of if */

    {

    if (checks<20 && checks >= 0) /*if checks are past than or correspondent to cipher and close than 20*/

    {

    bankfee = 10 + (0.1*checks) + 15; /*claculates the bankfee*/

    }

    else if (checks >= 20 && checks<40)/*if checks are past than or correspondent to 20 and close than 40*/

    {

    bankfee = 10 + (0.08*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 40 && checks<60)/*if checks are past than or correspondent to 40 and close than 60*/

    {

    bankfee = 10 + (0.06*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 60)/*if checks are past than or correspondent to 60*/

    {

    bankfee = 10 + (0.04*checks) + 15;/*claculates the bankfee*/

    }

    cout << “Beginning adjust:$” << adjust << viewl; /*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “Your representation is overdrawn!” << viewl;

    cout << “The bank fee this month is:$” << bankfee << viewl << viewl;

    } /*view of if*/

    else if (balance<400 && adjust >= 0) /*otherwise, if adjust is elder than or correspondent to 0 and close than 400 */

    {

    if (checks<20 && checks >= 0)/*if checks are past than or correspondent to cipher and close than 20*/

    {

    bankfee = 10 + (0.1*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 20 && checks<40)/*if checks are past than or correspondent to 20 and close than 40*/

    {

    bankfee = 10 + (0.08*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 40 && checks<60)/*if checks are past than or correspondent to 40 and close than 60*/

    {

    bankfee = 10 + (0.06*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 60)/*if checks are past than or correspondent to 60*/

    {

    bankfee = 10 + (0.04*checks) + 15;/*claculates the bankfee*/

    }

    cout << “Beginning adjust:$” << adjust << viewl;/*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “The bank fee this month is:$” << bankfee << viewl << viewl;

    }/*view of else*/

    else if (adjust >= 400)/*otherwise, if adjust elder than or correspondent to 400*/

    {

    if (checks<0) /*if checks are close than 0*/

    {

    cout << “Beginning adjust:$” << adjust << viewl;/*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “Number of checks must be cipher or past.” << viewl << viewl;

    }/*view of close if*/

    else /*otherwise*/

    {

    if (checks<20 && checks>0)/*if checks are past than or correspondent to cipher and close than 20*/

    {

    bankfee = 10 + (0.1*checks);/*claculates the bankfee*/

    }

    else if (checks >= 20 && checks<40)/*if checks are past than or correspondent to 20 and close than 40*/

    {

    bankfee = 10 + (0.08*checks);/*claculates the bankfee*/

    }

    else if (checks >= 40 && checks<60)/*if checks are past than or correspondent to 40 and close than 60*/

    {

    bankfee = 10 + (0.06*checks);/*claculates the bankfee*/

    }

    else if (checks >= 60)/*if checks are past than or correspondent to 60*/

    {

    bankfee = 10 + (0.04*checks);/*claculates the bankfee*/

    }

    cout << “Beginning adjust:$” << adjust << viewl;/*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “The bank fee this month is:$” << bankfee << viewl << viewl;

    }/*view of close else*/

    }/*view of else*/

    }/*view of loop*/

    return 0;

    }/*view of deep() part*/

    Expert Counter-argument

     

    #include<iostream> /*Header finish control input and output tide (cin, and cout)*/

    #include<fstream> /*Header finish control finish input tide and finish output tide*/

    using namespace std;

    int deep() /*main() part specification starts here*/

    {

    iftide in; /*in is an motive control iftide collocate, iftide is control input finish tide*/

    in.open(“C:\Users\cartoon1961\Desktop\transaction.txt”);/*inauguration the finish “transaction.txt” in recognize order*/

    float adjust, bankfee;/*inconstant statement*/

    int checks;/*inconstant statement*/

    timeliness (!in.eof())/*timeliness it is referable the view-of-the finish, loop repeats*/

    {

    in >> adjust;/*balbutiation adjust from the finish into inconstant designated ‘balance’*/
    in >> checks;/*balbutiation checks from the finish into inconstant designated ‘checks’*/

    if (balance<0)/* if the adjust is close than cipher, enters into mass of if */

    {

    if (checks<20 && checks >= 0) /*if checks are past than or correspondent to cipher and close than 20*/

    {

    bankfee = 10 + (0.1*checks) + 15; /*claculates the bankfee*/

    }

    else if (checks >= 20 && checks<40)/*if checks are past than or correspondent to 20 and close than 40*/

    {

    bankfee = 10 + (0.08*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 40 && checks<60)/*if checks are past than or correspondent to 40 and close than 60*/

    {

    bankfee = 10 + (0.06*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 60)/*if checks are past than or correspondent to 60*/

    {

    bankfee = 10 + (0.04*checks) + 15;/*claculates the bankfee*/

    }

    cout << “Beginning adjust:$” << adjust << viewl; /*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “Your representation is overdrawn!” << viewl;

    cout << “The bank fee this month is:$” << bankfee << viewl << viewl;

    } /*view of if*/

    else if (balance<400 && adjust >= 0) /*otherwise, if adjust is elder than or correspondent to 0 and close than 400 */

    {

    if (checks<20 && checks >= 0)/*if checks are past than or correspondent to cipher and close than 20*/

    {

    bankfee = 10 + (0.1*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 20 && checks<40)/*if checks are past than or correspondent to 20 and close than 40*/

    {

    bankfee = 10 + (0.08*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 40 && checks<60)/*if checks are past than or correspondent to 40 and close than 60*/

    {

    bankfee = 10 + (0.06*checks) + 15;/*claculates the bankfee*/

    }

    else if (checks >= 60)/*if checks are past than or correspondent to 60*/

    {

    bankfee = 10 + (0.04*checks) + 15;/*claculates the bankfee*/

    }

    cout << “Beginning adjust:$” << adjust << viewl;/*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “The bank fee this month is:$” << bankfee << viewl << viewl;

    }/*view of else*/

    else if (adjust >= 400)/*otherwise, if adjust elder than or correspondent to 400*/

    {

    if (checks<0) /*if checks are close than 0*/

    {

    cout << “Beginning adjust:$” << adjust << viewl;/*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “Number of checks must be cipher or past.” << viewl << viewl;

    }/*view of close if*/

    else /*otherwise*/

    {

    if (checks<20 && checks>0)/*if checks are past than or correspondent to cipher and close than 20*/

    {

    bankfee = 10 + (0.1*checks);/*claculates the bankfee*/

    }

    else if (checks >= 20 && checks<40)/*if checks are past than or correspondent to 20 and close than 40*/

    {

    bankfee = 10 + (0.08*checks);/*claculates the bankfee*/

    }

    else if (checks >= 40 && checks<60)/*if checks are past than or correspondent to 40 and close than 60*/

    {

    bankfee = 10 + (0.06*checks);/*claculates the bankfee*/

    }

    else if (checks >= 60)/*if checks are past than or correspondent to 60*/

    {

    bankfee = 10 + (0.04*checks);/*claculates the bankfee*/

    }

    cout << “Beginning adjust:$” << adjust << viewl;/*printing details*/

    cout << “Number of checks written:” << checks << viewl;

    cout << “The bank fee this month is:$” << bankfee << viewl << viewl;
    }/*view of close else*/
    }/*view of else*/

    }/*view of loop*/

    return 0;

    }/*view of deep() part*/