I'm not going to lie and say i fixed this but I did smooth out some rough edges. You can do the rest:
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
//function prototype
using namespace std;
void convert_type(char);
float calc_cost_hour(float, float);
int main() {
char item_code[10]="";
char item_name[20]="";
char item_type=' ';
float hours=(float)0.0;
float charge=(float)0.0;
int days=0;
float total_chrg=(float)0.0;
float total_hours=(float)0.0;
int counter=0;
char type_charge[7]="";
float cost_hour=(float)0.0;
float labor=(float)0.0;
float materials=(float)0.0;
float highest_charge=(float)0.0;
char itemCode[11]="";
int number_day=0;
//open input file
ifstream inFile;
inFile.open ("c:/program7.dat", ios::in);
//verify that open was successful
if (!inFile.fail()) //if open did not fail
{
//read data from prg7.dat file
cout<<"#"<<setw(6)<<"Type"<<setw(15)<<"Contr.Code"<<setw(13)<<"Item Name"<<setw(14)<<"Cost/Hour"<<setw(12)<<"Item Cost"<<endl;
cout<<endl;
cout<<setiosflags(ios::fixed);
cout<<setiosflags(ios::showpoint);
cout<<setprecision(2);
inFile >>item_code
>>item_name
>>item_type
>>hours
>>charge
>>days;
//test for the end of the file
while (!inFile.eof()) {
//function call
convert_type (item_type);
cost_hour=calc_cost_hour (charge, hours);
//update counter and accumulator
counter = counter + 1;
total_chrg = total_chrg + charge;
total_hours = total_hours + hours;
if (item_type=='L')
labor=labor+charge;
if (item_type=='M')
materials=materials+charge;
cout<< counter
<<setw(5) <<item_code
<<setw(4) <<item_name
<<setw(5) <<cost_hour
<<setw(9) <<charge<<endl;
if (charge > highest_charge) {
strcpy(itemCode, item_code);
number_day = days;
highest_charge = charge;
}
}//end while loop
//close file
inFile.close();
system("pause");
system("cls");
//Output items
cout<<"-----------------------------------------------------------------"<<endl;
cout<<"The number of records in the database is: "<<counter<<endl;
cout<<"Cost of all materials: "<<setw(15)<<materials<<endl;
cout<<"Total manhours charged: "<<setw(12)<<hours<<endl;
cout<<"Total labor cost: "<<setw(5)<<labor<<endl;
cout<<"The total cost of all charges: "<<setw(23)<<total_chrg<<endl;
cout<<endl;
cout<<"The contractor code that had the greatest expense was "<<itemCode<<" "<<endl;
cout<<"It was completed on day "<<number_day<<" of the job at a cost of $ "<<highest_charge<<" ";
cout<<endl;
cout<<endl;
}
}//end main
//function definition
void convert_type (char item_type) {
if(item_type=='C')
cout<<"CONTR"<<setw(2);
else if (item_type=='E')
cout<<"ELECT";
else if (item_type=='I')
cout<<"INSPC";
else if (item_type=='L')
cout<<"LABOR";
else if (item_type=='M')
cout<<"MATLS";
}
float calc_cost_hour (float charge, float hours) {
float cost_hour=(float)0.0;
if (hours!=(float)0.0)
cost_hour=charge/hours;
return 0;
}
One big one was void main. Don't do that anymore.