cant display the correct value of the structured values with function ... is it got to do wif some buffer stuff ???
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
const int MAXCHARS = 15;
const int NUMEMPS = 1;
int i;
struct EmpRec
{
long num;
char name[MAXCHARS];
double rate;
double hours;
};
int main()
{
int display();
EmpRec payroll[NUMEMPS];
for(i = 0; i < NUMEMPS; ++i)
{
cout << "\nEnter employee number: ";
cin >> payroll[i].num;
cout << "Enter employee name: ";
cin >> payroll[i].name;
cout << "Enter employee rate: ";
cin >> payroll[i].rate;
cout << "Enter employee hours worked: ";
cin >> payroll[i].hours;
}
for( i = 0; i < NUMEMPS; ++i)
cout << setiosflags(ios::left) << setw(12) << payroll[i].name
<< setiosflags(ios::right)
<< setw(6) << payroll[i].num
<< setiosflags(ios::showpoint | ios::fixed) << " "
<< setw(8) << setprecision(2)
<< (payroll[i].rate * payroll[i].hours) << endl;
display();
return 0;
}
int display()
{
EmpRec payroll[NUMEMPS];
for( i = 0; i < NUMEMPS; ++i)
cout << setiosflags(ios::left) << setw(12) << payroll[i].name
<< setiosflags(ios::right)
<< setw(6) << payroll[i].num
<< setiosflags(ios::showpoint | ios::fixed) << " "
<< setw(8) << setprecision(2)
<< (payroll[i].rate * payroll[i].hours) << endl;
cin.get();cin.ignore();
return 0;
}