Fixing Output
I need to format the date like mm/dd/yyyy by adding the / character. Any Ideas?
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
|
struct Info
{
char First[13];
char Last[13];
char ID[12];
char Date[9];
float Pay;
float Hours;
string Name()
{
stringstream full;
full<<Last<<", "<<First;
return full.str();
}
void ShowMe()
{
cout << First << " " <<Last<< endl
<< Date << endl
<< ID << endl
<< Hours << " @ " << Pay << endl << endl;
}
};
float average(float , float );
string newdate(string );
int main()
{
fstream BinIn;
Info Employees[100];
int sub=0;
float TotalGross = 0.0f;
float AvgGross;
BinIn.open(".\\Datafiles\\Lab5.bin",ios::in|ios::binary);
if(BinIn.fail())
{
cout<<"Unable to Process\n";
return 999;
}
while(BinIn.eof() == false)
{
BinIn.read(reinterpret_cast<char *>(&Employees[sub]),sizeof(Info));
sub++;
}
int maxElements = sub-1;
cout<<setw(50)<<"Bay West Industries"<<endl
<<setw(47)<<"Payroll Report"<<endl<<endl;
cout<<left<<setw(26)<<"Employee"
<<setw(12)<<"Date Hired"
<<setw(14)<<"ID"
<<setw(7)<<"Hours"
<<setw(7)<<"Rate"
<<setw(12)<<"Grosspay"<<endl;
cout<<setfill('-')
<<setw(78)<<'-'<<endl;
cout<<setfill(' ');
for(int index=0; index<maxElements; index++)
{
float gross = Employees[index].Hours * Employees[index].Pay;
cout<<left<<setw(26)<<Employees[index].Name()
<<setw(12)<<Employees[index].Date
<<setw(15)<<Employees[index].ID
//<<setprecision(2)<<fixed
<<setprecision(3)<<showpoint<<setw(3)<<Employees[index].Hours
<<right<<setprecision(4)<<showpoint<<setw(7)<<Employees[index].Pay
<<setw(10)<<setprecision(5)<<showpoint<<gross<<endl<<endl;
TotalGross = TotalGross + gross;
}
cout<<setfill('-')
<<setw(78)<<'-'<<endl;
cout<<setfill(' ');
cout<<setw(65)<<"Total Employees: "<<maxElements<<endl
<<setprecision(2)<<fixed
<<setw(65)<<"Total Gross Pay: "<<TotalGross<<endl
<<setw(66)<<"Average Gross Pay: "<<average(TotalGross, AvgGross)<<endl<<endl
<<setw(57)<<"Report Prepared By: Stephanie Precht"<<endl;
}
float average(float Total, float avg)
{
avg = Total / 17.0f;
return avg;
}
|
How is it currently formatted?
It is currently formatted as mmddyyyy. I just need to add the slashes.
If you only need to add the slashes for output, you could do something like
1 2
|
cout << Date[0] << Date[1] << '/' << Date[2] << Date[3]
<< '/' << Date[4] << Date[5] << Date[6] << Date[7]
|
It's not nice, but it would work. It could also be for-looped like
1 2 3 4 5 6 7
|
for ( int i = 0; i < 8; ++i )
{
if ( i == 2 || i == 4 )
cout << '/';
cout << Date[i];
}
|
Topic archived. No new replies allowed.