S
SK
Hi
I appreciate all of the feedback I have recieved. I am enjoying
working on my program and I hope that it can be appreciated. I have my
program compiling now and I am continuing to work out the bugs. I have
two problems that I cannot seem to resolve:
1. I want to have someone enter in as many employees as they want
to..and for each employee entered I would like to save the data from
that entry to print out at the end of the program. I continue to run
into a problem with the loop. I actually did not intend to use arrays
however I cannot seem to figure outany other way to approach the
problem.
2.This second problem is probably due to using arrays
intheprogram,however that being said I still want to figure this
out....I am trying to connect two strings together, concatenation. I
understandthat strncpy refers to n number of characters versus strcpy
is the actual character but the difficulty I am running into has to do
with the syntax. It is evident that I am somehow not correctly dealing
with putting things into memory and then extracting them. Any
thoughts??
//Specs to be added later
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME 20
# define EMPLOYEES 1000
//Global Defined Constant
const float OT = 1.5;
//Global Variable Declaratives
FILE*inp;
//Global Constants
# define FULLNAME 20
# define EMPLOYEES 1000
char fn[FULLNAME];
char ln[FULLNAME];
char department[20];
char again;
int count_EMP;
int number_EMP;
float wage;
float OTwage;
float hours;
float RegHr;
float RegHrPay;
float OTHrPay;
float OTHr;
float GrossPay;
int main(void)
{
/*Define the structure.*/
struct EMP_WeeklyPay
{
char first_name[FULLNAME];
char last_name[FULLNAME];
float RegHr;
float wage;
float OTHr;
float OTHrPay;
float GrossPay;
};
/*Rename the structure syntax.*/
typedef struct EMP_WeeklyPay EWP;
/*Create an array of structures.*/
EWP emp[EMPLOYEES];
/*Counters*/
int n, numemp;
int count = 0;
printf("\n\nMountain Pacific Corporation\n");
printf("Department Salary Program\n\n");
printf("Please enter the name of the department: ");
scanf("%s", department);
/*Loop to read in employee wage data*/
count_EMP = 0;
count_EMP++;
for (n = 0; n < EMPLOYEES; ++n){
do{
printf("\nEnter employee # %d: ", count_EMP);
scanf("%s %s", &fn, &ln);
printf("\nPlease enter the hourly wage for the employee:
");
scanf("%f", &wage);
printf("\nPlease enter the number of hours worked this"
" week: ");
scanf("%f", &hours);
printf("\nThank you. Process another employee?");
scanf("%s", &again);
}while(again == 'Y' || again == 'y');
/*Read in the input*/
numemp = scanf("%11s%11s%f%f%f%f%f", &fn, &ln, &RegHr,
&wage, &OTHr, &OTHrPay, &GrossPay);
/*Check if user is done*/
if(again != 'Y' && again !='y');
printf("End of processing\n\n\n");
/*Process the input*/
if(numemp == 6)
{
if (RegHr > 40)
{
OTHr = hours - 40;
OTHrPay = OT * OTHr * wage;
RegHrPay = 40.0 * wage;
}
else
{
RegHrPay = hours * wage;
OTHrPay = 0.0;
}
GrossPay = RegHrPay + OTHrPay;
strncpy(emp[n].first_name, fn, FULLNAME);
emp[n].first_name[FULLNAME] = '\0';
strncpy(emp[n].last_name, ln, FULLNAME-1);
emp[n].last_name[FULLNAME-1] = '\0';
emp[n].RegHr = RegHr;
emp[n].wage = wage;
emp[n].OTHr = OTHr;
emp[n].OTHrPay = OTHrPay;
emp[n].GrossPay = GrossPay;
++count;
}
/*Print Table*/
printf("\n\nMountain Pacific Corporation\n");
printf("Department Salary Program\n\n");
printf("Employee Reg Hrs "
"Overtime Hrs Gross\n");
printf("-----------------------------------------"
"-------------------------\n\n");
for(n=0; n < count; ++n) {
printf("%-35s%-17s%12f%10f%12f%10f%%5f",
emp[n].first_name,
emp[n].last_name, emp[n].RegHr,
emp[n].wage, emp[n].OTHr, emp[n].OTHrPay,
emp[n].GrossPay);
}
}
}
I appreciate all of the feedback I have recieved. I am enjoying
working on my program and I hope that it can be appreciated. I have my
program compiling now and I am continuing to work out the bugs. I have
two problems that I cannot seem to resolve:
1. I want to have someone enter in as many employees as they want
to..and for each employee entered I would like to save the data from
that entry to print out at the end of the program. I continue to run
into a problem with the loop. I actually did not intend to use arrays
however I cannot seem to figure outany other way to approach the
problem.
2.This second problem is probably due to using arrays
intheprogram,however that being said I still want to figure this
out....I am trying to connect two strings together, concatenation. I
understandthat strncpy refers to n number of characters versus strcpy
is the actual character but the difficulty I am running into has to do
with the syntax. It is evident that I am somehow not correctly dealing
with putting things into memory and then extracting them. Any
thoughts??
//Specs to be added later
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME 20
# define EMPLOYEES 1000
//Global Defined Constant
const float OT = 1.5;
//Global Variable Declaratives
FILE*inp;
//Global Constants
# define FULLNAME 20
# define EMPLOYEES 1000
char fn[FULLNAME];
char ln[FULLNAME];
char department[20];
char again;
int count_EMP;
int number_EMP;
float wage;
float OTwage;
float hours;
float RegHr;
float RegHrPay;
float OTHrPay;
float OTHr;
float GrossPay;
int main(void)
{
/*Define the structure.*/
struct EMP_WeeklyPay
{
char first_name[FULLNAME];
char last_name[FULLNAME];
float RegHr;
float wage;
float OTHr;
float OTHrPay;
float GrossPay;
};
/*Rename the structure syntax.*/
typedef struct EMP_WeeklyPay EWP;
/*Create an array of structures.*/
EWP emp[EMPLOYEES];
/*Counters*/
int n, numemp;
int count = 0;
printf("\n\nMountain Pacific Corporation\n");
printf("Department Salary Program\n\n");
printf("Please enter the name of the department: ");
scanf("%s", department);
/*Loop to read in employee wage data*/
count_EMP = 0;
count_EMP++;
for (n = 0; n < EMPLOYEES; ++n){
do{
printf("\nEnter employee # %d: ", count_EMP);
scanf("%s %s", &fn, &ln);
printf("\nPlease enter the hourly wage for the employee:
");
scanf("%f", &wage);
printf("\nPlease enter the number of hours worked this"
" week: ");
scanf("%f", &hours);
printf("\nThank you. Process another employee?");
scanf("%s", &again);
}while(again == 'Y' || again == 'y');
/*Read in the input*/
numemp = scanf("%11s%11s%f%f%f%f%f", &fn, &ln, &RegHr,
&wage, &OTHr, &OTHrPay, &GrossPay);
/*Check if user is done*/
if(again != 'Y' && again !='y');
printf("End of processing\n\n\n");
/*Process the input*/
if(numemp == 6)
{
if (RegHr > 40)
{
OTHr = hours - 40;
OTHrPay = OT * OTHr * wage;
RegHrPay = 40.0 * wage;
}
else
{
RegHrPay = hours * wage;
OTHrPay = 0.0;
}
GrossPay = RegHrPay + OTHrPay;
strncpy(emp[n].first_name, fn, FULLNAME);
emp[n].first_name[FULLNAME] = '\0';
strncpy(emp[n].last_name, ln, FULLNAME-1);
emp[n].last_name[FULLNAME-1] = '\0';
emp[n].RegHr = RegHr;
emp[n].wage = wage;
emp[n].OTHr = OTHr;
emp[n].OTHrPay = OTHrPay;
emp[n].GrossPay = GrossPay;
++count;
}
/*Print Table*/
printf("\n\nMountain Pacific Corporation\n");
printf("Department Salary Program\n\n");
printf("Employee Reg Hrs "
"Overtime Hrs Gross\n");
printf("-----------------------------------------"
"-------------------------\n\n");
for(n=0; n < count; ++n) {
printf("%-35s%-17s%12f%10f%12f%10f%%5f",
emp[n].first_name,
emp[n].last_name, emp[n].RegHr,
emp[n].wage, emp[n].OTHr, emp[n].OTHrPay,
emp[n].GrossPay);
}
}
}