I'm working on this program and need help! For some reason the while loop is not recognizing the end of file int he text file.
Here's my code:
Any help would be appreciated!Code:transIn.open("trans1.txt"); while (!transIn.eof()) { withdrawalAmt = 0.0; depositAmt = 0.0; transAmt = 0.0; numTrans = 0; transIn >> acctChar >> acctNum >> begBal; ch = transIn.peek(); if (ch != '\n') { do { transIn >> transChar; if (transChar == 'W') { transIn >> transAmt; withdrawalAmt = withdrawalAmt + transAmt; numTrans++; } else if (transChar == 'D') { transIn >> transAmt; depositAmt = depositAmt + transAmt; numTrans++; } ch = transIn.peek(); } while (ch != '\n'); } cout << fixed << showpoint << setprecision(2); cout << acctChar << acctNum << " " << begBal << endl; cout << withdrawalAmt << " " << depositAmt << " " << numTrans << endl; }



LinkBack URL
About LinkBacks


