Hey guys,
I need help again :sad:. I'm doing really well in the class, it just seems like these past couple assignments have been really rushed (i.e., we went over chapter 5 the day after I finished reading chapter 4 =/). I'm getting sort of discouraged, because up to now I've been able to do everything right, and have actually had a few people ask me questions. I hope I can stop bothering everyone with questions twice a day. Anyways, here's the problem. Maybe someone could diagnose the logic error, as it compiles smoothly. I continue to get the defaul case in the switch...
Also, I know it's very sloppy, but if you have any tips on how to keep it neat, please let me know!! :mrgreen:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
const double INT_RATE = 0.05;
const double SVC_CHGE = 25.00;
const double MIN_BAL = 1000.00;
double begBal, wAmt, dAmt, xactAmt, intPaid, bal;
int acctNo, totWd, totDep;
char xactCode;
totWd = totDep = 0;
bool svcChgd = false;
ifstream inFile;
ofstream outFile;
inFile.open("inData.txt");
/*if (inFile != "inData.txt")
return 1;*/
outFile.open("outData.txt");
outFile << fixed << showpoint << setprecision(2);
inFile >> acctNo >> begBal >> xactCode >> xactAmt;
if (begBal < MIN_BAL)
{
begBal -= SVC_CHGE;
svcChgd = true;
}
bal = begBal;
while (!inFile.eof())
switch (xactCode)
{
case 'D': case 'd':
bal += xactAmt;
totWd++;
case 'I': case 'i':
bal += xactAmt;
intPaid = xactAmt;
case 'W': case 'w':
bal -= xactAmt;
totWd++;
if (bal < MIN_BAL && svcChgd == false)
{
bal -= SVC_CHGE;
svcChgd = true;
}
default:
cout << "Invalid Transaction Code...\nTerminating Program..." << endl;
return 1;
}
outFile << bal; //just testing the code... didn't work =/
}
If you're planning on helping, I'm sure you can tell what the program is supposed to do. If you need me to put down a disc. I can...
Variables:
const double INT_RATE = 0.05; //interest rate
const double SVC_CHGE = 25.00; //service charge if bal falls below 1000
const double MIN_BAL = 1000.00; //minimum balance allowed
double begBal, wAmt, dAmt, xactAmt, intPaid, bal; //wAmt = total withd amt, xact = transaction amt, intPaid = interest paid
int acctNo, totWd, totDep; // totWd = total numbers of withd
char xactCode; // transaction code - either a W D or I
bool svcChgd = false; // if already been charged a service fee, switch to true.
Thanks guys!