i have this program but it will only read the first two values twice of my data file and the second value it reads as the first variable C , how do i fix this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// develop algorithm to balance checking account
// make transactions and charge service charges
#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"
int main ()
{
// variables
char next_char; // used to hold end of line marker
char C , D , E , alphabet , Z ;
float beginning_balance ,cnumber , dnumber , service_charge_cheque , number;
float current_balance, service_charge_500 , service_charge_D;
float additional_service_charge;
// service charges
service_charge_cheque = 0.15;
service_charge_500 = 5.00;
service_charge_D = 0.10;
additional_service_charge = 1.00;
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()) // end of file
{
// begin with your starting balance
ins >> beginning_balance;
// output results to file
outs << "Your beginning balance is $" << beginning_balance << endl;
outs << endl;
ins >> alphabet;
C = alphabet;
D = alphabet;
E = alphabet;
if ( C = alphabet )
{
ins >> number;
outs << "You have cashed a cheque for $ " << number << endl;
outs << "You are charged a service charge of $0.15 is applied when cashing a cheque" << endl;
current_balance = beginning_balance - number - service_charge_cheque;
outs << "Your new account balance is $ " << current_balance << endl;
}
outs << endl;
if ( current_balance < 500.00 )
{
outs << "Your current account balance has dropped below $500.00"<< endl;
outs << "A service charge of $5.00 will be applied"<< endl;
current_balance = current_balance - service_charge_500;
outs << "Your current balance is $ " << current_balance << endl;
}
if ( D = alphabet )
{
ins >> number;
outs << "You have made a deposit of $ " << number << endl;
outs << "You will be charged a service fee of $0.10"<< endl;
current_balance = current_balance + number - service_charge_D;
outs << "Your current balance is $ " << current_balance << endl;
}
if (current_balance < 50.00 )
{
outs << "Warning: You have less than $50.00 in your account" << endl;
}
if (current_balance < 0 )
{
outs << "Your account has become negative " << endl;
outs << "An additional service charge of $1.00 will be ";
outs << "charged for everychque deposited until balance is positive" << endl;
number = number + additional_service_charge;
}
outs << endl;
if (alphabet != C || alphabet != D || alphabet != E )
{
outs << "error in transaction " << endl;
}
ins.get(next_char); //skip end of line character
return 0;
}
// end main
//getch();
ins.close(); // closing input file
outs.close(); // closing output file
}
|
this is my input
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
and my output is :
Your beginning balance is $879.46
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