Programming C++

Sep 24, 2013 at 11:26am
The ATM Transaction Validator requires a loop and if-then logic. You will write the output to a file called statement.txt and read in a file called customer.txt which contains the following information on each line of the file:

Customer last name (two words followed by a comma as a delimiter)
Checking account balance
Transaction type code
Transaction amount

Provide an appropriate error message if the file cannot be found.
Remember to echo each input item as well
A negative amount should cause an error message to be written and the transaction ignored
Invalid transaction types must be reported as errors
All monetary values should be printed with 2 decimal places.

Transaction type codes are (W)ithdraw, (D)eposit, (R)eport the balance

At the end of the transaction the program writes out the new balance or why it couldn't be done.

In any case, if the ending balance is below $300, a warning message should be printed

You need to create the input data file (customer.txt) and use the following data to test your program:
Joe Turing, 4124.50 D 200
Charles Babbage, 300.00 D 100
Sam Backus, 350.25 W 51
Sam Hopper, 600.50 X 600
Robert McCarthy, 1000.00 R 0
Jack Atanasoff, 200.00 W 200
Anne Stroustrup, 300.75 W 301
Amanda Hollerith, 500.00 W -2
Sep 24, 2013 at 12:03pm
Readme First sticky wrote:
Don't post homework questions
Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.

You did not show your attempt, nor did you present any specific question.
Sep 24, 2013 at 12:26pm
Ok...Thanks... I have attempted the question..Can't produce the output



Sep 25, 2013 at 1:07am
This is the code I have so far

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

void main()
{
double amtDeposited = 0.0;
double amtReported = 0.0;
double amtWithdrawn = 0.0;

string custName = "", type = "";
double Checkingaccountbalance;
char Transactiontypecode;
double Transactionamount;

ifstream fin("customer.txt");
ofstream fout("statement.txt");
fout << showpoint << fixed << setprecision(2);

while(!fin.eof())
{
fin >> custName;
fin >> Checkingaccountbalance;
fin >> Transactiontypecode;
fin >> Transactionamount;

fout << "Name: " << custName << endl;
fout << "Accountbalance: " << Checkingaccountbalance << endl;
fout << "Transaction: " << Transactiontypecode << endl;
fout << "Amount: " << Transactionamount << endl;

switch (Transactiontypecode)
{
case 'W':
type = "Withdraw";
Sep 25, 2013 at 1:12am
You need a getline with a delimiter.
http://www.cplusplus.com/reference/string/string/getline/
Sep 25, 2013 at 1:31am
Can you show me an example? of a getline How does the code look so far?
Sep 25, 2013 at 1:34am
getline(cin, name, ',');
Sep 25, 2013 at 1:58am
Would I put that in the while loop?
Sep 25, 2013 at 3:52am
of course
Topic archived. No new replies allowed.