Hi there.
I've been pestering my TA's for a few days about the problem with my current program, but they've not responded yet. I'm approaching the crunch period (due tomorrow at noon) and I would really like to get this thing figured out. I was hoping someone could look at the code and point me in the direction of finding what I screwed up.
The basic objective of the program is to record and track transactions that the users enter. There will only be five types of input.
Initial balance: integer
-1 (terminates the program)
Three types of transactions:
ATM follows this format: 2008 1 22 -200 0 (5th number is always a 0)
Checks are: 2008 1 23 -150 3356 (check number varies)
Deposits are: 2008 1 25 200 (No 5th number)
The year will always be 2008, but the month/date will vary, along with the amount. Deposit is always positive, atm/check is negative.
The problem right now is that the program isn't terminating when the -1 is entered. I've tried a do while loop, a while loop, I've tried throwing an if statement in the body of the loop to break when -1 is detected. You have to use -1 for all 5 entries before it breaks.
int main()
{
double startBalance, endBalance, maxBalance, minBalance, amountAtm, amountDep, amountCheck, amount, totalLoops, balance;
int year, month, day, startMonth, spCol, startYear, startDay, lastMonth, lastYear, lastDay, numAtm, numCheck, numDep;
numDep = 0;
numAtm = 0;
numCheck = 0;
amountAtm = 0;
amountDep = 0;
amountCheck = 0;
totalLoops = 0;
startBalance = 0;
startYear = 0;
startDay = 0;
startMonth = 0;
cin >> startBalance;
balance = startBalance;
maxBalance = balance;
minBalance = balance;
while(year != -1)
{
cin >> year;
cin >> month;
cin >> day;
cin >> amount;
if(amount < 0)
{
cin >> spCol;
if(spCol == 0)
numAtm ++, amountAtm = (amountAtm + amount), balance = (balance + amount);
else
numCheck ++, amountCheck = (amountCheck + amount), balance = (balance + amount);
}
else
numDep ++, amountDep = (amountDep + amount), balance = (balance + amount);
if(balance > maxBalance)
maxBalance = balance;
else
if(balance < minBalance)
minBalance = balance;
totalLoops ++;
}
lastYear = year;
lastMonth = month;
lastDay = day;
endBalance = balance;
cout << "Starting Balance: " << startBalance << endl;
cout << "Ending Balance: " << endBalance << endl;
cout << "\n";
cout << "Start Transaction: " << startYear << " " << startMonth << " " << startDay << endl;
cout << "Ending Transaction: " << lastYear << " " << lastMonth << " " << lastDay << endl;
cout << "\n";
cout << "Number of Deposits: " << numDep << " | Total: " << amountDep << endl;
cout << "Number of Checks: " << numCheck << " | Total: " << amountCheck << endl;
cout << "Number of ATMs: " << numAtm << " | Total: " << amountAtm << endl;
cout << "\n";
cout << "Minimum Balance: " << minBalance << endl;
cout << "Maximum Balance: " << maxBalance << endl;
return 0;
}