Error Check & Total Sum Help!
Mar 19, 2014 at 10:13pm UTC
I am new to C++ programming so please bare with me. I have two easy questions. 1) I am attempting to calculate the total sum for all values that appear under my "Interest" column.
2) When I compile the below code, the program ends at INPUT AND OUTPUT TEXT FILES WERE OPENED SUCCESSFULLY. I figure its a loop issue but am not sure of how to correct this. I need the INPUT AND OUTPUT TEXT FILES WERE OPENED SUCCESSFULLY.
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
#include<iomanip>
#include<iostream>
#include<fstream>
using namespace std;
int main(){
system("color f0" );
ifstream fin;
ofstream fout;
fin.open("Input3.txt" );
fout.open("output.txt" );
if (!fin){
cout<<"Input failure\n" ;
system("pause" );
return 1;
}
if (fout){
cout<<"INPUT AND OUTPUT TEXT FILES WERE OPENED SUCCESSFULLY\n\n" ;
system("pause" );
return 1;
}//
cout<<left<<setw(20)<<"FULL NAME"
<<setw(13)<<"CARD #"
<<setw(10)<<"BALANCE"
<<setw(9)<<"APR (%)"
<<setw(7)<<"INTEREST" <<endl;
string firstName, lastName;
float balance, payment, interest, averageDailyBalance, unpaidBal, APR, totalInterest;
long cardNumber;
int d1, d2;
while (!fin.eof()){//end of file while
fin>>firstName>>lastName>>cardNumber>>balance>>payment>>d1>>d2;
//calculations
averageDailyBalance = (balance*d1-payment*d2)/d1;
if (averageDailyBalance < 100){
APR=5;
}
else if (averageDailyBalance >=100 && averageDailyBalance <=1000){
APR=10;
}
else {
APR=15;
}
interest = averageDailyBalance*APR/(100*12);
totalInterest = sum
//output
cout<<fixed<<left<<showpoint<<setprecision(2)
<<setw(20)<<firstName+" " +lastName
<<setw(13)<<cardNumber
<<right<<setw(7)<<balance
<<setw(9)<<APR
<<setw(10)<<interest<<endl;
}//end of "end of file: controlled while
for (int count=0; count<60;count++) cout<<"-" ;
cout<<endl<<endl;
for (int count=0; count<60;count++) cout<<"*" ;
cout<<endl<<endl;
cout"Total interest owered to Bank is $" <<
fin.close();
fout.close();
system("pause" );
return 0;
}//end of main
Mar 19, 2014 at 10:18pm UTC
That's what I thought initially, but when I changed it to 0, the same thing occurred. I even tried to remove the return 1 altogether, and the same issue occurred
Mar 19, 2014 at 10:24pm UTC
When you open a new file it has nothing so it is at the end. ( I think)
Why open file for output if you don't use it?
Mar 19, 2014 at 10:37pm UTC
I didnt add my fout statements yet, even though the output file is currently blank, there is an output text file and it does open successfully.
Topic archived. No new replies allowed.