Change of program

Discussion in 'C Programming' started by SK, Nov 13, 2005.

  1. SK

    SK Guest

    Hi
    I am trying a simpler version of a program I was trying to write. The
    idea is to have someone enter the information and then at the end of
    the program display all of the info. in a table. I have a feeling the
    errors I am making are probably stupid but I would appreciate any
    imput.

    //Specs to be added later

    //C Libraries
    #include <stdio.h>
    #include <math.h>
    #include <string.h>

    //Global Variable Declaratives
    FILE*inp;

    char Fname[10];
    char Lname[10];
    char department[20];
    char again;
    char FULLNAME[30];

    int count_EMP;
    int number_EMP;

    float wage;
    float OTwage;
    float hours;
    float RegHr;
    float RegHrPay;
    float OTHrPay;
    float OTHr;
    float GrossPay;



    //Function Prototypes
    void GetInfo(void);
    void Process(void);
    void Report(void);

    int main(void)
    {

    GetInfo();

    system("pause");

    return 0;
    }


    void GetInfo(void)
    {


    do{


    printf("\nPlease enter the first and last name of the
    employee:");
    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("\nDo you want to enter another employee into the
    payroll for"
    "week?");
    scanf("%s", &again);


    }while(again == 'Y' || again == 'y');




    if (RegHr > 40)
    {
    OTHr = hours - 40;
    OTHrPay = 1.5 * OTHr * wage;
    RegHrPay = 40.0 * wage;
    }

    else
    {
    RegHrPay = hours * wage;
    OTHrPay = 0.0;

    }

    GrossPay = RegHrPay + OTHrPay;





    if(count_EMP>=1);

    for (count_EMP = 0;
    count_EMP < number_EMP;
    count_EMP++);

    strcpy(FULLNAME, Fname);
    strcat(FULLNAME, Lname);



    scanf("%s%f%f%f\n\n", &FULLNAME, &RegHr, &OTHr, &GrossPay);


    if(again != 'Y' && again !='y');
    printf("End of processing\n\n\n");

    printf("\n\nMountain Pacific Corporation\n");
    printf("Department Salary Program\n\n");
    printf("Department: %s\n\n", department);

    printf("Employee Reg Hrs "
    "Overtime Hrs Gross\n");
    printf("-----------------------------------------"
    "-------------------------\n\n");

    printf("%-20s%11.2f%11.2f%11.2f", FULLNAME, RegHr, OTHr,
    GrossPay);





    }
     
    SK, Nov 13, 2005
    #1
    1. Advertising

  2. On 13 Nov 2005 12:31:38 -0800, "SK" <> wrote:

    >Hi
    >I am trying a simpler version of a program I was trying to write. The
    >idea is to have someone enter the information and then at the end of
    >the program display all of the info. in a table. I have a feeling the
    >errors I am making are probably stupid but I would appreciate any
    >imput.
    >
    >//Specs to be added later
    >
    >//C Libraries
    >#include <stdio.h>
    >#include <math.h>
    >#include <string.h>
    >
    >//Global Variable Declaratives
    >FILE*inp;
    >
    >char Fname[10];
    >char Lname[10];
    >char department[20];
    >char again;
    >char FULLNAME[30];
    >
    >int count_EMP;
    >int number_EMP;
    >
    >float wage;
    >float OTwage;
    >float hours;
    >float RegHr;
    >float RegHrPay;
    >float OTHrPay;
    >float OTHr;
    >float GrossPay;
    >
    >
    >
    >//Function Prototypes
    > void GetInfo(void);
    > void Process(void);
    > void Report(void);
    >
    >int main(void)
    > {
    >
    > GetInfo();
    >
    > system("pause");
    >
    > return 0;
    > }
    >
    >
    >void GetInfo(void)
    > {
    >
    >
    > do{
    >
    >
    > printf("\nPlease enter the first and last name of the
    >employee:");
    > scanf("%s %s", &Fname, &Lname);


    The %s formats require the corresponding arguments to be pointers to
    char. The arguments you provide are pointers to array of char. On
    most systems this difference is probably irrelevant but it pays to do
    it right. Remove the &s.

    >
    > printf("\nPlease enter the hourly wage for the employee: ");


    Output that does not end with a \n may not be visible when the system
    waits for user input. If you want the input on the same line as the
    prompt, use fflush to flush the output stream.

    > scanf("%f", &wage);
    >
    > printf("\nPlease enter the number of hours worked this week:
    >");
    > scanf("%f", &hours);
    >
    >
    > printf("\nDo you want to enter another employee into the
    >payroll for"
    > "week?");
    > scanf("%s", &again);
    >
    >
    > }while(again == 'Y' || again == 'y');


    If the user answers yes, the new input will replace all the previous
    input which will never be processed.

    >
    >
    >
    >
    > if (RegHr > 40)
    > {
    > OTHr = hours - 40;
    > OTHrPay = 1.5 * OTHr * wage;
    > RegHrPay = 40.0 * wage;


    You are very inconsistent with your constants. Here you use 40 and
    40.0. Not a technical problem but when you come back to the program
    after several months it will be just another confusion factor.

    > }
    >
    > else
    > {
    > RegHrPay = hours * wage;
    > OTHrPay = 0.0;
    >
    > }
    >
    > GrossPay = RegHrPay + OTHrPay;
    >
    >
    >
    >
    >


    Is there some reason for all this wasted vertical space? It only
    serves to disrupt the visual flow of the program.

    > if(count_EMP>=1);
    >
    > for (count_EMP = 0;
    > count_EMP < number_EMP;
    > count_EMP++);


    Where do any of these get incremented?

    >
    > strcpy(FULLNAME, Fname);
    > strcat(FULLNAME, Lname);


    Do you really want DoeJohn as the result?

    >
    >
    >
    > scanf("%s%f%f%f\n\n", &FULLNAME, &RegHr, &OTHr, &GrossPay);


    Did you mean printf here? If so, remove all the &s. Why would you
    print here and then again below? What was your real intent?

    >
    >
    > if(again != 'Y' && again !='y');


    Based on the do while above, again cannot be 'Y' or 'y'.

    > printf("End of processing\n\n\n");
    >
    > printf("\n\nMountain Pacific Corporation\n");
    > printf("Department Salary Program\n\n");
    > printf("Department: %s\n\n", department);
    >
    > printf("Employee Reg Hrs "
    > "Overtime Hrs Gross\n");
    > printf("-----------------------------------------"
    > "-------------------------\n\n");
    >
    > printf("%-20s%11.2f%11.2f%11.2f", FULLNAME, RegHr, OTHr,
    >GrossPay);


    You probably want a \n at the end of the format string.

    >
    >
    >
    >
    >
    >}



    <<Remove the del for email>>
     
    Barry Schwarz, Nov 15, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Q. John Chen
    Replies:
    0
    Views:
    356
    Q. John Chen
    Nov 15, 2006
  2. Q. John Chen
    Replies:
    0
    Views:
    312
    Q. John Chen
    Nov 15, 2006
  3. Suganya
    Replies:
    0
    Views:
    464
    Suganya
    Apr 29, 2008
  4. Hemant

    Change Framework 3.5 to 2.0 change

    Hemant, Nov 13, 2009, in forum: ASP .Net
    Replies:
    5
    Views:
    1,707
    Digvijay Singh
    Nov 16, 2009
  5. tom c
    Replies:
    1
    Views:
    210
    PeterKellner
    Jun 8, 2006
Loading...

Share This Page