Source Code To Pseudocode For Payroll Program
Source Code To Pseudocode For Payroll Program
h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#define MAX_EMPS 50
typedef struct
{
int day;
int month;
int year;
} PayDate;
char fname[30];
char lname[30];
int hrs;
int days;
int rate;
int insuranceNo;
int insuranceValue;
int payeValue ;
int payeNo;
int healthValue;
int healthNo;
int grossSalary;
int netSalary;
PayDate date;
} Employee;
Employee emp[MAX_EMPS];
int num_emps = 0;
void add_employee()
{
system ("cls"); //closes the last screen and opens to this screen in transition
system ("color 4E"); // Changes the Background Colour & Text of the Program
// Validation to checks if maximum number of employees have been reached
if (num_emps == MAX_EMPS)
{
printf("\nError: maximum number of employees reached\n");
return;
}
int tempHrs = 0;
int tempDays = 0;
int tempRate = 0;
char tempNib[16];
char tempPaye[16];
char tempHealth[16];
char valid;
system ("cls");//closes the last screen and opens to this screen in transition
printf ("\t\tSECTION 1 - First & Last Names and Hours & Days Worked\n");
printf ("\nPlease ensure that the Employee's First & Last Names ");
printf ("\nare spelt correctly and the amount of letters in ");
printf ("\nhis/her names, should not exceed 30 characters,");
printf ("\nas well as their work days and hours, which should not ");
printf ("\nexceed seven (7) days, per week or twelve (12) hours, per day.\n");
printf ("\nand their rate of pay should be over minimum wage. \nthank you!\n");
valid = 'N';
do{
printf("\nEnter First Name: ");
scanf("%s", tempFname);
strcpy(emp[num_emps].fname, tempFname);
valid = 'N';
do{
printf("\nEnter Last Name: ");
scanf("%s", tempLname);
strcpy(emp[num_emps].lname, tempLname);
valid = 'N';
do {
printf("\nEnter Hours Worked per Day: ");
scanf("%d", &tempHrs);
valid = 'N';
do {
printf("\nEnter Days Worked per Week: ");
scanf("%d", &tempDays);
if (tempDays > 7)
{
printf("\nError: Employee's work days should not be more than seven (7),
per week!");
printf("\nWHY DO THEY WORK ON SUNDAYS???\n\n");
}
else {
valid = 'Y';
}
}
while
(valid == 'N');
emp[num_emps].days = tempDays;
valid = 'N';
do {
printf("\nEnter the Hourly Rate of Pay : $");
scanf("%d", &tempRate);
emp[num_emps].payeValue = 10;
emp[num_emps].healthValue =
emp[num_emps].insuranceValue = 11;
system ("pause");
system ("cls");//closes the last screen and opens to this screen in transition
system ("color 4F"); // Changes the Background Colour & Text of the Program
printf ("\t\tSECTION 2 - National Insurance, Pay As You Earn & Health Surcharge
ID#\n");
printf ("\nPlease ensure that the Employee's NIB, PAYE & Health Surcharge IDs
are");
printf ("\ncorrect and the amount of numbers in");
printf (" the identification, should not exceed 15 numbers,\nthank you!\n");
valid = 'N';
do {
scanf("%s", &tempNib);
if (strlen(tempNib) > 15) // check if NIB is more than 15 digits
{
printf("\nError: NIB number must be no more than 15 digits\n");
}
else {
valid = 'Y';
}
}
while
(valid == 'N');
emp[num_emps].insuranceNo = atol(tempNib);
valid = 'N';
do {
scanf("%s", &tempPaye);
valid = 'N';
do {
scanf("%s", &tempHealth);
}
else {
valid = 'Y';
}
}
while
(valid == 'N');
emp[num_emps].healthNo = atol(tempHealth);
system ("pause");
system("cls");
system("color 2F");
char response;
num_emps++;
printf("\nEmployee added successfully!\n");
system("pause");
}
void sort_employees()
{
system ("cls");
system ("color 42");
int i, j;
for (i = 0; i < num_emps-1; i++)
{
for (j = 0; j < num_emps-i-1; j++)
{
if (emp[j].netSalary < emp[j+1].netSalary)
{
Employee temp = emp[j];
emp[j] = emp[j+1];
emp[j+1] = temp;
}
}
}
printf("Employees sorted by total salary\n");
system ("pause");
}
void display_all_employees()
{
system ("cls");
system ("color 24");
int i;
}
system ("pause");
}
void export_employees_to_file() {
if (outputFile == NULL) {
printf("Error: could not open file for writing\n");
return;
}
fclose(outputFile);
void import_employees_from_file() {
if (inputFile == NULL) {
printf("Error: could not open file for reading\n");
return;
}
int num_imported = 0;
fscanf(inputFile, "%d\n", &num_imported);
fclose(inputFile);
num_emps = num_imported;
switch (choice)
{
case 1:
add_employee();
break;
case 2:
sort_employees();
break;
case 3:
display_all_employees();
break;
case 4:
export_employees_to_file();
break;
case 5:
import_employees_from_file();
break;
case 6:
goodbye();
return;
default:
printf("Invalid choice\n");
}
system ("pause");// pause the program
}
}
int main(void)
{
welcome();
main_menu();
return 0;
}