Re: seemingly stupid C program issue

  • From: "John Miller" <n1umj@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 31 Oct 2007 14:25:09 -0400

OK, that wasn't done in the class so-called example, but now that you mention that it was mentioned briefly at the beginning of the notes, and it works. Thanks, I guess now this assignment is done. 1 more to go, I hope it's not too bad. I'll find out Monday, he'll put it out Friday but I'm out of here this weekend again so I won't see it until Monday. ----- Original Message ----- From: "Jackie McBride" <abletec@xxxxxxxxx>

To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, October 31, 2007 1:58 PM
Subject: Re: seemingly stupid C program issue


John, if u have a string, u gotta enclose it in quotes.  So, connie
Cobol & all other names, & any other strings, need 2 b enclosed in
quote marks.

On 10/31/07, John Miller <n1umj@xxxxxxxxxxx> wrote:
Hi all, I got the homework 6, answer the teacher posted to use as a template
for making the next assignment, homework 7, strings. Now, in this code, I
did exactly what he said, and way down in the main area, you'll see the
names before the employee numbers which is basically all we had to do. For
some reason, it doesn't like the first name, claims it's a "un declared
identifier". Is there something I'm missing or what's goign on there? I
followed the instructions being told this is the easiest one yet and this
was pretty much all I had to do, I went over and over it and don't see if I
missed something and what's strange it only has a problem with the first
name of the 5. I commented it so anyoen looking at it will know, I commented it as the problem name. Can anyone give me a clue what's goign on here? This
is very different from the last program I posted.

(start code)
#include <stdio.h>

#define DATA_SETS 5

#define STD_HOURS 40.0

#define OT_RATE 1.5



/****************************************/

/* Structure Declarations */

/****************************************/

struct employee /* Structure to store associate data */

{

char name[20]; /*employee names*/

long id_number; /* Member: Stores Clock ID Number */

float wage; /* Member: Stores hourly wage */

float hours; /* Member: Stores number of hours worked */

float overtime; /* Member: Stores number of overtime hours worked */

float gross; /* Member: Stores gross pay */

};



/************************************************************************/

/* Function: input_hours_worked */

/* */

/* Purpose: Obtains input from user, the number of hours worked for */

/* each employee based on clock number. The number of */

/* hours worked are passed back to 'main', where they are */

/* assigned to the array hours_worked. */

/* */

/* Parameters: n - Data set #. */

/* clock - Employee's clock number */

/* */

/* Returns: hours: The number of hours worked. */

/* */

/************************************************************************/

float input_hours_worked ( int n, int clock )

{

/* Local Declarations */

float hours; /* Number of hours worked by employee */

float hours_in_a_week = 168.0; /* Max hours in a work week */

printf ( "\n" );

printf ( "Data Set #%i\n", n + 1 );

printf ( "Clock Number: %06i\n", clock );

printf ( "Enter Hours Worked: " );

scanf_s ( "%f", &hours ); /* Read in the number of hours worked */

/* Test for user error */

if( ( hours >= 0.0 ) && ( hours < hours_in_a_week ) )

return hours; /* Return the number of hours worked */

else

return ( -1.0 ); /* Return Error */

} /* End of input_hours_worked function */



/************************************************************************/

/* Function: calculate_overtime_hours */

/* */

/* Purpose: Calculate the amount of overtime worked based on a 40 */

/* hour work week. */

/* */

/* Parameters: hours - Number of hours worked */

/* */

/* Returns: A value equal to the number of overtime hours worked. */

/* If no overtime was worked, then 0.0 is returned. */

/* */

/************************************************************************/

float calculate_overtime_hours ( float hours )

{

/* Calculate Overtime Hours */

if( hours > STD_HOURS )

return ( hours - STD_HOURS ); /* Return the amount of overtime worked */

else

return ( 0.0 ); /* Return that no overtime was worked */

} /* End calculate_overtime function */



/************************************************************************/

/* Function: calculate_gross_pay */

/* */

/* Purpose: Calculate the total gross pay based on the amount of */

/* time that was worked. This includes overtime pay, if */

/* applicable. */

/* */

/* Parameters: ot - Overtime hours worked */

/* hours - Regular hours worked */

/* wage_per_hour - Hourly wage for employee */

/* */

/* Returns: Returns a value that is equal to the gross pay due to */

/* the employee. */

/* */

/************************************************************************/

float calculate_gross_pay ( float ot, float hours, float wage_per_hour )

{

if( ot > 0 )

return ( wage_per_hour * ( STD_HOURS + ( ot * OT_RATE ) ) );

else

return ( wage_per_hour * hours );

} /* End calculate_gross_pay function */



/************************************************************************/

/* Function: display_wage_data */

/* */

/* Purpose: To display all employee information to the screen. */

/* */

/* Parameters: worker - Array of structures with all employee info */

/* size - number of array elements to process */

/* */

/* Returns: Nothing. */

/* */

/************************************************************************/

void display_wage_data ( struct employee worker[], int size )

{

/* Local Declarations */

int n; /* loop and array index */

/* Print out header */

printf ( "\n\n" );

printf ( "---------------------------------------------------\n" );

printf ( "Clock#\t Wage Hours\t OT\t Gross \n" );

printf ( "---------------------------------------------------\n" );

/* Print data for each employee */

for( n=0; n < size; ++n )

{

printf ( "%06i\t%5.2f\t%4.1f\t%4.1f\t%6.2f\n",

worker[n].id_number,

worker[n].wage,

worker[n].hours,

worker[n].overtime,

worker[n].gross );

} /* End for loop */

} /* End display_wage_data function */



/************************************************************************/

/* Function: error_check */

/* Purpose: To report any error to the user. */

/* */

/* Parameters: hours - Hours entered by user */

/* */

/* Returns: Nothing. */

/* */

/************************************************************************/

void error_check ( hours )

float hours;

{

/* see if error condition on hours exists */

if( hours == -1.0 )

{

printf ( "An invalid entry has been made.\n" );

printf ( "Please start over.\n" );

exit (1);

} /* End of if statement */

} /* End error_check function */



/*****************/

/* MAIN */

/*****************/

main()

{

/* Local Declarations */

struct employee associate[DATA_SETS] = /* Array of structures storing */

/* all associate data */

{

{ /*where problem is seemign to be, this name*/

Connie Cobol, 98401, 10.60, 0, 0, 0

}

,

{

Mary Apl, 526488, 9.75, 0, 0, 0

}

,

{

Frank Fortran, 765349, 10.50, 0, 0, 0

}

,

{

Jeff Ada, 34645, 12.25, 0, 0, 0

}

,

{

Anton Pascal, 127615, 8.35, 0, 0, 0

}


};

int n; /* Loop Counter */

/* Introduce User to program */

printf ( "WAGE CALCULATOR\n" );

printf ( "Please input the number of Hours Worked for each Employee(ie.
Clock Number)\n" );

/* Loop for inputting and processing wage data */

for( n=0; n < DATA_SETS; ++n )

{

associate[n].hours = input_hours_worked ( n, associate[n].id_number );

error_check ( associate[n].hours );

associate[n].overtime = calculate_overtime_hours ( associate[n].hours );

associate[n].gross = calculate_gross_pay ( associate[n].overtime,

associate[n].hours,

associate[n].wage );

} /* End of for loop */

/* Print out information on employees */

display_wage_data ( associate, DATA_SETS );

} /* End of Main */

(end code)

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind




--
Jackie McBride
Please join my fight against breast cancer
<http://teamacs.acsevents.org/site/TR?px=1790196&pg=personal&fr_id=3489>
& Check out my homepage at:
www.abletec.serverheaven.net
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: