S
SK
Hi
I am trying to teach myself how to program in C. I am a physician
hoping to be able to help restructure my office. Anyhow, I amhoping
that the porblem I am having is simple to those much more experienced
in programming. I am trying to use the concept of arrays to calculate
the hours of my backoffice staff, however I am getting a ridiculous
amount of error lines. If any one has time to help me that would be
great. I am using the free devc++ compiler.
Thanks in advance to anyone who offers some advice.
SK
//Specs to be added later
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME[20]
# define EMPLOYEES[1000]
/*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 EMP_WeeklyPay EWP;
/*Create an array of structures.*/
EWP emp[EMPLOYEES];
/*Counters*/
int n, numemp;
int count = 0;
/*Strings in input*/
char department[20], fn[FULLNAME], ln[FULLNAME], char again;
/*temporary float*/
float wage, float OTwage, float hours, float RegHr,
float OTHrPay, float OTHr, float GrossPay;
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*/
for (n = 0; n < EMPLOYEES; ++n){
printf("\nEnter employee # %d: ", count_EMP);
scanf("%s %s", &Fname, &Lname);
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);
}
/*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*/
printf("\nThank you. Process another employee?");
scanf("%s", &again);
while(again == 'Y' || again == 'y');
if(again != 'Y' && again !='y');
printf("End of processing\n\n\n");
/*Process the input*/
if(num == 7)
{
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(employee[n].first_name, fn, FULLNAME-1);
employee[n].first_name[FULLNAME-1] = '\0';
strncpy(employee[n].last_name, ln, FULLNAME-1);
employee[n].last_name[FULLNAME-1] = '\0';
employee[n].regularhours = RegHr;
employee[n].wage = wage;
employee[n].overtimehours = OTHr;
employee[n].overtimepay = OTHrPay;
employee[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",
employee[n].first_name,
employee[n].last_name, employee[n].RegHr,
employee[n].wage, employee[n].OTHr, employee[n].OTHrPay,
employee[n].GrossPay);
}
}
I am trying to teach myself how to program in C. I am a physician
hoping to be able to help restructure my office. Anyhow, I amhoping
that the porblem I am having is simple to those much more experienced
in programming. I am trying to use the concept of arrays to calculate
the hours of my backoffice staff, however I am getting a ridiculous
amount of error lines. If any one has time to help me that would be
great. I am using the free devc++ compiler.
Thanks in advance to anyone who offers some advice.
SK
//Specs to be added later
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME[20]
# define EMPLOYEES[1000]
/*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 EMP_WeeklyPay EWP;
/*Create an array of structures.*/
EWP emp[EMPLOYEES];
/*Counters*/
int n, numemp;
int count = 0;
/*Strings in input*/
char department[20], fn[FULLNAME], ln[FULLNAME], char again;
/*temporary float*/
float wage, float OTwage, float hours, float RegHr,
float OTHrPay, float OTHr, float GrossPay;
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*/
for (n = 0; n < EMPLOYEES; ++n){
printf("\nEnter employee # %d: ", count_EMP);
scanf("%s %s", &Fname, &Lname);
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);
}
/*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*/
printf("\nThank you. Process another employee?");
scanf("%s", &again);
while(again == 'Y' || again == 'y');
if(again != 'Y' && again !='y');
printf("End of processing\n\n\n");
/*Process the input*/
if(num == 7)
{
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(employee[n].first_name, fn, FULLNAME-1);
employee[n].first_name[FULLNAME-1] = '\0';
strncpy(employee[n].last_name, ln, FULLNAME-1);
employee[n].last_name[FULLNAME-1] = '\0';
employee[n].regularhours = RegHr;
employee[n].wage = wage;
employee[n].overtimehours = OTHr;
employee[n].overtimepay = OTHrPay;
employee[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",
employee[n].first_name,
employee[n].last_name, employee[n].RegHr,
employee[n].wage, employee[n].OTHr, employee[n].OTHrPay,
employee[n].GrossPay);
}
}