I need help with a pretty simple program please

This is a discussion on I need help with a pretty simple program please within the C Programming forums, part of the General Programming Boards category; okay this is what i have: #include <stdio.h> main() { float clock_num; /*Employee clock number*/ float hrs_worked; float hrly_wage; float ...

  1. #1
    Unregistered
    Guest

    I need help with a pretty simple program please

    okay this is what i have:

    #include <stdio.h>
    main()
    {
    float clock_num; /*Employee clock number*/
    float hrs_worked;
    float hrly_wage;
    float gross_pay;

    printf("Enter the clock number:");
    scanf("%f",&clock_num);
    printf("Enter your hourly wage:");
    scanf("%f",&hrly_wage);
    printf("Enter number of hours worked:");
    scanf("%f",&hrs_worked);


    gross_pay=hrs_worked*hrly_wage;

    printf("Your gross pay is $%i\n", gross_pay);
    }



    but he wants it like this:

    -------------------------------------------
    clock # wage hours gross
    -------------------------------------------
    384243 10.60 51.0 540.60

    (FYI: the clock number is just random, it doesnt have anythign to do with the calculation)

    i just can't seem to get the cursor to do what i want it to do. please help. thanks!

  2. #2
    Unregistered
    Guest
    can anyone help?

  3. #3
    My diaper's full....... stevey's Avatar
    Join Date
    Nov 2001
    Posts
    759
    #include <stdio.h>
    int main()
    {
    long clock_num; /*Employee clock number*/
    float hrs_worked;
    float hrly_wage;
    float gross_pay;


    printf("Enter the clock number ( six digits) :");
    scanf("%li",&clock_num);
    printf("Enter your hourly wage:");
    scanf("%f",&hrly_wage);
    printf("Enter number of hours worked:");
    scanf("%f",&hrs_worked);


    gross_pay=hrs_worked*hrly_wage;

    printf ("Clock # Wage Hours Gross\n\n");
    printf("%li %4.2f %4.1f %.2f", clock_num,hrly_wage,hrs_worked,gross_pay);

    return 0;
    }
    Steve

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    85

    Red face

    Remember I/O library in C is not reliable.
    Here is my simple solution. Although it does not
    exactly match with your intended purpose, but
    this may give you a alternative to make input and
    output on the same line.

    #include <conio.h> /* for clrscr() */
    #include <stdio.h>

    int main()
    {
    float clock_num; /*Employee clock number*/
    float hrs_worked;
    float hrly_wage;
    float gross_pay;

    printf("Enter the clock number:");
    scanf("%f",&clock_num);
    printf("Enter your hourly wage:");
    scanf("%f",&hrly_wage);
    printf("Enter number of hours worked:");
    scanf("%f",&hrs_worked);

    gross_pay=hrs_worked*hrly_wage;

    clrscr(); /* clear screen */
    printf("clock # wage hours gross\n");
    printf("%f%f%f%%f\n",clock_num,hrs_worked,
    hrly_wage,gross_pay);
    return 0;
    }
    Note: You need to setfield to align output in good format.(such as "%4.2f"..)
    Hope it give you an idea!
    DV007

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Why is that no-one appears to check the return code from scanf()? Do we all trust the user that much?

    Code:
    if (scanf("%f", &myfloat) == 1)
        printf("You entered %f\n", myfloat);
    else
         printf("Invalid!!\n");
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    My diaper's full....... stevey's Avatar
    Join Date
    Nov 2001
    Posts
    759
    course i always check return values.
    but i thought best to restrict the answer to the level of the question.
    Steve

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-27-2005, 08:50 PM
  2. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM
  3. Simple Networking Program in C
    By osal in forum C Programming
    Replies: 4
    Last Post: 05-30-2004, 11:46 AM
  4. Simple Program not working right (in C)
    By DruzeTito in forum C Programming
    Replies: 5
    Last Post: 06-01-2002, 10:14 PM
  5. Pretty Print Program
    By 2TheGrindStone in forum C++ Programming
    Replies: 5
    Last Post: 11-16-2001, 11:16 AM

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