Feb 17, 2010 at 4:59pm UTC
Hello,
I am new to programming and am having a bugger of a time trying to get this code to write to an output file. I also can't seem to get it to read all of the information from the input file?
Any information would be helpful, thank you.
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
ifstream fin;
ofstream fout;
double beginningBalance = 0.0;
char transactionType;
double transactionAmount;
double accountBalance;
string name = "";
const double MINIMUM_BALANCE = 300.00;
fin.open("customer.txt");
if (!fin)
{
cout << "File does not exist." << endl;
return 1;
}
fout.open("customeroutput.out");
fout << fixed << showpoint;
fout << setprecision(2);
fin >> name;
fin >> beginningBalance;
accountBalance = beginningBalance;
fin >> transactionType >> transactionAmount;
while(!fin.eof())
{
switch (transactionType)
{
case 'D':
case 'd':
accountBalance = beginningBalance + transactionAmount;
break;
case 'B':
case 'b':
accountBalance = accountBalance;
break;
case 'W':
case 'w':
accountBalance = beginningBalance - transactionAmount;
if (accountBalance < MINIMUM_BALANCE)
cout << "Warning, you are below your minimum account balance." << endl;
break;
default:
cout << "Invalid transaction code." << endl;
}
fin >> transactionType >> transactionAmount;
}
fout << "Customer Name: " << name << endl;
fout << "Checking Balance Before Transaction: " << beginningBalance << endl;
fout << "Transaction Type: " << transactionType << endl;
fout << "Transaction Amount: " << transactionAmount << endl;
fout << "Checking Balance after Transaction: " << accountBalance << endl;
return 0;
}