add something that I'm missing

I need calculate the highest charge but it comes out to be 0. I have the output shown. Does anyone see what i have to add?


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

void Welcome();
void OpenFiles(ifstream & fin, ofstream & fout);
void PrintHeader(ofstream & fout);
double CalLateCharge(int lateDays, double rentFee, double percent);
void LineOutput(int equipcode, int lateDays, double rentFee, double percent, double lateCharge, ofstream & fout);
void PrintHigh(ofstream & fout,double highestCharge);

int main(){

//Define Varibles
double lateCharge;
double percent;
double rentFee;
double highestCharge;
int lateDays;
int equipCode;

ifstream fin;
ofstream fout;

Welcome();

OpenFiles(fin,fout);
PrintHeader(fout);
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);

fin >> equipCode;
fin >> lateDays;
fin >> rentFee;
fin >> percent;

//Bring in information from file
while(!fin.eof()){
lateCharge = CalLateCharge(lateDays, rentFee, percent);
LineOutput( equipCode, lateDays, rentFee, percent, lateCharge, fout);
fin >> equipCode;
fin >> lateDays;
fin >> rentFee;
fin >> percent;
}

PrintHigh(fout, highestCharge);
fin.close();
fout.close();
return 0;
}

// Welcome Function
void Welcome(){
cout << "\nWelcome to Al's Rental Supply, Inc. Computer Program\n" << endl;
cout << "ENTER 'pico Report.out' in the terminal to access the Equipment Report\n\n";
return;
}

// Open I/O Files
void OpenFiles(ifstream & fin, ofstream & fout){
fin.open("LateEquip.data");
if(fin.fail()){
cout << "\nInput File Error\n";
exit(1);
}
fout.open("Report.out");
if(fout.fail()){
cout << "\nOutput File Error\n";
exit(2);
}
return;
}

//Display Company Heading
void PrintHeader(ofstream & fout){
fout << endl;
fout << " Al's Rental Supply, Inc.\n";
fout << " Delinquent Equipment Report\n" << endl;
fout << " EQUIP CODE LATE DAYS $RENTAL FEE PERCENT $LATE CHARGE\n";
return;
}

//Late Charge Calculation
double CalLateCharge(int lateDays, double rentFee, double percent){
int count = 1;
double lateCharge;
double previousLate = 0.00;
double highestCharge = -99999999.99;
while(lateDays>0){ lateCharge = rentFee * (percent/100) * count + previousLate;
previousLate = lateCharge;
count++;
lateDays--;

//Find Highest Charge
if (lateCharge > highestCharge)
highestCharge = lateCharge;
}
return lateCharge;
return highestCharge;
}

//Line Output
void LineOutput(int equipCode, int lateDays, double rentFee, double percent, double lateCharge, ofstream & fout){
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);
fout << " ";
fout << equipCode;
fout << setw(12);
fout << lateDays;
fout << setw(13);
fout << rentFee;
fout << setw(11);
fout << percent;
fout << setw(13);
fout << lateCharge;
fout << endl;
return;
}

//Print highest charge
void PrintHigh(ofstream & fout,double highestCharge){
fout << endl;
fout << "HIGHEST_LATE_CHARGE:";
fout << setw(5);
fout << highestCharge << endl;
}

output


Al's Rental Supply, Inc.
Delinquent Equipment Report

EQUIP CODE LATE DAYS $RENTAL FEE PERCENT $LATE CHARGE
194 14 545.00 8.99 5144.53
205 6 75.00 5.75 90.56
234 12 25.99 4.00 81.09
652 4 300.00 10.00 300.00
679 3 1200.00 10.00 720.00
718 5 100.00 10.00 150.00
755 10 50.99 5.50 154.24
783 5 2999.99 15.75 7087.48
804 2 10999.99 18.50 6104.99
884 25 199.99 12.75 8287.09
890 30 45.00 6.50 1360.13

HIGHEST_LATE_CHARGE: 0.00





Last edited on
Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/


Because of the missing indention it's hard to tell. But I guess that it has to do with:
1
2
3
4
5
6
7
//Find Highest Charge
if (lateCharge > highestCharge)
highestCharge = lateCharge;
}
return lateCharge;
return highestCharge;
}
please assign some value to highestCharge variable
Topic archived. No new replies allowed.