what do these warnings mean

This is a discussion on what do these warnings mean within the C Programming forums, part of the General Programming Boards category; How do i get rid of them Here my code #include <stdio.h> #include <math.h> int main() { float grosspay, rate, ...

  1. #1
    Unregistered
    Guest

    what do these warnings mean

    How do i get rid of them

    Here my code

    #include <stdio.h>
    #include <math.h>
    int main()
    {
    float grosspay, rate, orate, rpay, opay, ei, parkfee, cpp, ud, ft, pst,
    gst;
    int hours, overtime;

    do
    {
    printf("Enter number of hours worked:\n " );
    scanf( "%d", &hours );
    {
    if (hours >40)
    printf("The number of regular hours should not exceed 40\n");
    }
    {
    if (hours < 0)
    printf("The number of regular hours should be greater than 0\n");
    }
    }
    while(hours > 40 || hours < 0);


    do
    {
    printf("Enter number of overtime hours worked:\n");
    scanf( "%d", &overtime);
    {
    if (overtime >72)
    printf("The number of overtime hours should not exceed 72\n");
    }
    }
    while (overtime>72);

    printf( "Enter hourly rate of the worker: $ " );
    scanf( "%f", &rate );

    orate = (float) (rate * 1.5);
    rpay = (float) (rate*hours);
    opay = (float) (orate*overtime);
    grosspay = (float) (rpay + opay);
    ei = (float) (grosspay * 0.02);
    cpp = (float) (grosspay * 0.025);
    ud = (float) (grosspay * 0.015);
    ft = (float) (grosspay * 0.3);
    parkfee = 5.00;
    pst = (float) (parkfee * 0.08);
    gst = (float) (parkfee * 0.07);

    printf("---Payment Summary---\n\n\n");
    printf("Regular Hours: %d\n" , hours);
    printf("Overtime Hours: %d\n\n" , overtime);

    printf("Hourly rate: $%.2f; ", rate);
    printf("Overtime rate (x1.5): $%.2f\n\n" , orate);

    printf("Regular Pay: $%.2f\n", rpay);
    printf("Overtime Pay: $%.2f\n\n\n", opay);

    printf("Gross Pay is: $%.2f\n", grosspay);

    printf("Deductions:\n");
    printf("EI (2%%) $.2f\n", ei);
    printf("CPP (2.5%%) $.2f\n", cpp);
    printf("Health Plan $45.00\n");
    printf("Union Dues (1.5%%) $.2f\n", ud);
    printf("Federal Tax (30%%) $.2f\n", ft);
    printf("Parking Fee $5.00\n");
    printf("Parking PST (8%%) $.2f\n", pst);
    printf("Parking GST (7%%) $.2f\n", gst);
    printf("Car Payment Dedcution $150.00\n");
    printf("Charatable Donation Deduction $10.00\n");

    return 0;
    }

    cc-1198 cc: WARNING File = ass.c, Line = 64
    The format string ends before this argument.

    printf("EI (2%%) $.2f\n", ei);
    ^

    cc-1198 cc: WARNING File = ass.c, Line = 65
    The format string ends before this argument.

    printf("CPP (2.5%%) $.2f\n", cpp);
    ^

    cc-1198 cc: WARNING File = ass.c, Line = 67
    The format string ends before this argument.

    printf("Union Dues (1.5%%) $.2f\n", ud);
    ^

    cc-1198 cc: WARNING File = ass.c, Line = 68
    The format string ends before this argument.

    printf("Federal Tax (30%%) $.2f\n", ft);
    ^

    cc-1198 cc: WARNING File = ass.c, Line = 70
    The format string ends before this argument.

    printf("Parking PST (8%%) $.2f\n", pst);
    ^

    cc-1198 cc: WARNING File = ass.c, Line = 71
    The format string ends before this argument.

    printf("Parking GST (7%%) $.2f\n", gst);
    ^

  2. #2
    Unregistered
    Guest
    the hats are under the word after the comma
    ex ,ei
    ^

  3. #3
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    You seem to be missing some '%' in your printf's.

  4. #4
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    just fine under DOS

    running it under DOS is just fine I Compiled it. Stand alone closes before i can view the results.

    using C:\dm\bin> new > text.txt

    Enter number of hours worked: 12
    Enter number of overtime hours worked: 12
    Enter hourly rate of the worker: $ 0.23


    Regular Hours: 12
    Overtime Hours: 12

    Hourly rate: $0.23; Overtime rate (x1.5): $0.34

    Regular Pay: $2.76
    Overtime Pay: $4.14


    Gross Pay is: $6.90
    Deductions:
    EI (2%) $.2f
    CPP (2.5%) $.2f
    Health Plan $45.00
    Union Dues (1.5%) $.2f
    Federal Tax (30%) $.2f
    Parking Fee $5.00
    Parking PST (8%) $.2f
    Parking GST (7%) $.2f
    Car Payment Dedcution $150.00
    Charatable Donation Deduction $10.00
    Last edited by bljonk; 02-07-2002 at 02:48 PM.
    Ünicode¬>world = 10.0£

  5. #5
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    running it under DOS is just fine
    Yes but the output is wrong because of missing '%'s

    Check your output results bljonk
    Enter hourly rate of the worker: $ 0.23
    I hope you earn more than that lol
    Last edited by C_Coder; 02-07-2002 at 02:57 PM.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    > cc-1198 cc: WARNING File = ass.c, Line = 64
    > The format string ends before this argument.
    > printf("EI (2%%) $.2f\n", ei);
    It means you have more printf arguments (in this case ei is one argument too many), when compared to the number of conversions (in this case, none at all) in the printf control string.

    If you want to print a float, it's "%.2f", not $ as you have written it.

  7. #7
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    Cool wow! slow there dude

    quo:
    I was just wondering about it
    Ünicode¬>world = 10.0£

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Some comments to your code. First take a look at this while-loop:

    Code:
    do 
    { 
      printf("Enter number of hours worked:\n " ); 
      scanf( "%d", &hours ); 
      if (hours >40) 
        printf("The number of regular hours should not exceed 40\n"); 
     
      else if (hours < 0) 
        printf("The number of regular hours should be greater than 0\n");     
    } 
    while(hours > 40 || hours < 0);
    I made the second if a else-if. If hours > 40, then hours < 0 is FALSE. So when hours > 40, it would be a waste of time to check if hours < 0.

    Further I removed the unnecessary brackets. The same for the next while-loop.

    Code:
    do 
    { 
      printf("Enter number of overtime hours worked:\n"); 
      scanf( "%d", &overtime); 
    
      if (overtime >72) 
        printf("The number of overtime hours should not exceed 72\n"); 
    } 
    while (overtime>72);
    This

    Code:
    parkfee = 5.00;
    is a little inefficient. The variable parkfree is used as a constant, why not make a define? It saves a variable and assignment-time. By the way, I see a lot of constant numbers in the calculations. It would be better to make defines with logical names to define those constants.

    1. It makes the code more readable.
    2. It makes the code better maintanable.

    When changes need to be make, you just take a look at your constants and change them. Then in the whole program they are changed and you don't need to worry about forgetting to change one of them somewhere around in the code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice on removing valid (but minor) compiler warnings
    By PaulBlay in forum C Programming
    Replies: 12
    Last Post: 04-20-2009, 12:16 PM
  2. Warnings when using vector of vector
    By Boksha in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2008, 01:54 PM
  3. Replies: 9
    Last Post: 03-14-2008, 09:55 AM
  4. Warnings from String manipulation functions.
    By Arker in forum C Programming
    Replies: 4
    Last Post: 10-14-2002, 11:59 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21