This is the part of my code writing to the file:
cout << "Would you like to save this checkbook to a file? (Y/N): ";
cin >> save;
if (toupper(save)=='Y')
{
fout.open("balance.txt", ios::app);
fout << "***************************************************************"<< endl;
fout << "********* C H E C K B O O K B A L A N C E S H E E T **********"<< endl;
fout << "***************************************************************"<< endl;
fout << endl;
fout << endl;
fout << setw(10) << "Deposits" << setw(20) << "Withdrawals" << setw(30) << "Balance"<< endl;
fout << "***************************************************************"<< endl;
fout << setw(60) << currentBal<< endl;
for (i=0; i<with; i++)
{
currentBal = currentBal - wAmt[i];
fout << setw(20) << "$" << wAmt[i] << setw(35) << currentBal << endl;
}//end for
for (j=0; j<dep; j++)
{
currentBal = currentBal + dAmt[j];
fout << " $"<< dAmt[j] << setw(52) << currentBal << endl;
}//end for
fout << "***************************************************************"<< endl;
fout << "***************************************************************"<< endl;
fout << endl;
fout << endl;
fout.close();
cout << "Would you like to balance another checkbook? (Y/N) :";
cin >> another;
}
else if (toupper(save)=='N')
{
cout << "Would you like to balance another checkbook? (Y/N) :";
cin >> another;
}
When I input for example, that the starting balance is 200, one withdrawal of 100 and one deposit of 100 so the final balance is 200, this is what the balance.txt file shows:
Quote
***************************************************************
********* C H E C K B O O K B A L A N C E S H E E T **********
***************************************************************
Deposits Withdrawals Balance
***************************************************************
-367220
***************************************************************
***************************************************************
***************************************************************
********* C H E C K B O O K B A L A N C E S H E E T **********
***************************************************************
Deposits Withdrawals Balance
***************************************************************
-367308
***************************************************************
***************************************************************
***************************************************************
********* C H E C K B O O K B A L A N C E S H E E T **********
***************************************************************
Deposits Withdrawals Balance
***************************************************************
200
$100 100
$100 200
***************************************************************
***************************************************************
********* C H E C K B O O K B A L A N C E S H E E T **********
***************************************************************
Deposits Withdrawals Balance
***************************************************************
-367220
***************************************************************
***************************************************************
***************************************************************
********* C H E C K B O O K B A L A N C E S H E E T **********
***************************************************************
Deposits Withdrawals Balance
***************************************************************
-367308
***************************************************************
***************************************************************
***************************************************************
********* C H E C K B O O K B A L A N C E S H E E T **********
***************************************************************
Deposits Withdrawals Balance
***************************************************************
200
$100 100
$100 200
***************************************************************
***************************************************************
As you can see, there are a few random checkbook balancesheets and then the final one is the correct one. I'm not sure if there is a problem with how I'm saving it to the file, but I can't seem to figure out why it's like this. I tried to write my code based off of my book/what I could find online.

New Topic/Question
Reply



MultiQuote



|