i cant get my program to read the rest of my variables from my data file it will only read the first two and my end of file wont work it keeps continuing on. how can i fix this
879.46
C 400.00
D 100.0
F 525.00
C 450.00
D 500.00
D 1000.00
C 2000.00
D 3000.00
D 3500.00
C 5500.00
C 500.00
B 200.00
C -235.00
D 250.00
H -500.00
D 500.00
E
thats my data it will only read the inital number and C and D but nothing else.
// February 15, 2014
// develop algorithm to balance checking account
// make transactions
#include<iostream> // required for keyboard and screen I/O
#include<fstream> // required for external file stream
#include<iomanip>
#include<conio.h>
#include<string>
using namespace std;
// associating program identifiers with external file names
#define in_file "data.txt"
#define out_file "result.txt"
void main ()
{
// variables
char C , D , E , alphabet , Z , next_char ;
float beginning_balance ,cnumber , dnumber , service_charge_cheque , number;
float current_balance, service_charge_500 , service_charge_D;
float additional_service_charge;
ifstream ins; // associates ins as an input stream
ofstream outs; // associates outs as an output stream
ins.open( in_file );
outs.open (out_file);
while (!ins.eof())
{
// begin with your starting balance
ins >> beginning_balance;
cout << "Your beginning balance is $" << beginning_balance << endl;
cout << endl;
ins >> alphabet;
C = alphabet;
D = alphabet;
E = alphabet;
if ( alphabet = C )
{
ins >> number;
cout << "You have cashed a cheque for $ " << number << endl;
cout << "You are charged a service charge of $0.15 is applied when cashing a cheque" << endl;
current_balance = beginning_balance - number - service_charge_cheque;
cout << "Your new account balance is $ " << current_balance << endl;
}
cout << endl;
if ( current_balance < 500.00 )
{
cout << "Your current account balance has dropped below $500.00"<< endl;
cout << "A service charge of $5.00 will be applied"<< endl;
current_balance = current_balance - service_charge_500;
cout << "Your current balance is $ " << current_balance << endl;
}
if ( alphabet = D )
{
ins >> number;
cout << "You have made a deposit of $ " << number << endl;
cout << "You will be charged a service fee of $0.10"<< endl;
current_balance = current_balance + number - service_charge_D;
cout << "Your current balance is $ " << current_balance << endl;
}
if (current_balance < 50.00 )
{
cout << "Warning: You have less than $50.00 in your account" << endl;
}
if (current_balance < 0 )
{
cout << "Your account has become negative " << endl;
cout << "An additional service charge of $1.00 will be ";
cout << "charged for everychque deposited until balance is positive" << endl;
cnumber = cnumber + additional_service_charge;
}
cout << endl;
if (alphabet != C || alphabet != D || alphabet != E )
{
cout << "error in transaction " << endl;
}
i got return 0 to work and now its not running in a infinite loop but the program is only reading my first value , i'm assuming it has something to do with my if statement but im not sure how i would be change it
You have cashed a cheque for $ 400
You are charged a service charge of $0.15 is applied when cashing a cheque
Your new account balance is $ 479.31
Your current account balance has dropped below $500.00
A service charge of $5.00 will be applied
Your current balance is $ 474.31
You have made a deposit of $ 400
You will be charged a service fee of $0.10
Your current balance is $ 874.21