ok so i got the program to run and display the employees on the screen. But im having a hard time displaying the new information after i call the "RaiseSalary" and "FindHighestPaid" function. When i call the results onto the screen with the "DisplayEmployee" function i just get zeros. If anyone can tell me why i would appreciate it. thanx. heres the code and header.
.c file:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "employee.h"
int main()
{
double PercentOfRaise;
employee * p;
int N;
int i;
PercentOfRaise = .06;
printf("How many employees are there?");
fflush(stdout);
scanf("%d", &N);
p = (employee *)malloc(N * sizeof (employee));
for(i = 0;i < N; i++)
{
printf("Enter the data for employee %d\n:", i);
fflush(stdout);
*(p + i) = CollectData();
}
for(i = 0; i < N; i++)
{
DisplayEmployee (&p[i]);
}
RaiseSalary (&p[i], N, PercentOfRaise);
DisplayEmployee (&p[i]);
FindHighestPaid (&p[i], N);
DisplayEmployee (&p[i]);
return 0;
}
Header file (employee.h):
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
typedef struct employee
{
long ID;
char FirstName[20];
char LastName[30];
double Salary;
char StreetAddress[50];
char City[30];
char State[4];
char ZipCode[10];
char Telephone[13];
} employee;
void ClearInputBuffer();
employee CollectData();
void RaiseSalary(employee * p, int N, double PercentOfRaise);
employee FindHighestPaid(employee * p, int Length);
void DisplayEmployee(employee * p);
void ClearInputBuffer()
{
while(getchar() != '\n')
continue;
}
employee CollectData()
{
employee p;
printf("Enter ID:");
fflush(stdout);
scanf("%ld", &p.ID);
ClearInputBuffer();
printf("Enter first name:");
fflush(stdout);
scanf("%s", &p.FirstName[20]);
printf("Enter last name:");
fflush(stdout);
scanf("%s", &p.LastName[30]);
printf("Enter the Street Address:");
fflush(stdout);
gets(&p.StreetAddress[50]);
ClearInputBuffer();
printf("Enter the city:");
fflush(stdout);
scanf("%s", &p.City[30]);
printf("Enter the state:");
fflush(stdout);
scanf("%s", &p.State[2]);
printf("Enter the zipcode:");
fflush(stdout);
scanf("%s", &p.ZipCode[10]);
printf("Enter the telephone number:");
fflush(stdout);
scanf("%s", &p.Telephone[13]);
printf("Enter the salary:");
fflush(stdout);
scanf("%lf", &p.Salary);
return p;
}
void RaiseSalary(employee * p, int N, double PercentOfRaise)
{
int i;
for(i = 0; i < N; i++)
{
(p + i) -> Salary += ((p + i) -> Salary) * PercentOfRaise;
}
}
employee FindHighestPaid(employee * p, int N)
{
employee q;
int i;
q = *p;
for(i = 1; i < N; i++)
{
if(((p + i) -> Salary > q.Salary))
{
q = *(p + i);
}
}
return q;
}
void DisplayEmployee(employee * p)
{
printf("----------------------------------------------\n");
printf("\t %s \t %ld \t %.2lf \t\n", p -> LastName, p -> ID, p -> Salary);
}