salary program heeeeeeeelp....

This is a discussion on salary program heeeeeeeelp.... within the C Programming forums, part of the General Programming Boards category; HJi, im a rookie on this . I've been working on this for 4 hours and I don't seem to ...

  1. #1
    juan
    Guest

    salary program heeeeeeeelp....

    HJi, im a rookie on this . I've been working on this for 4 hours and I don't seem to spot the problems on this salary program. Its supposed to compute salaries for 4 types of workers. It is working just fine until the following line:
    while ( paycode = getchar() .........................

    can u help me out? thanks a lot..






    #include <stdio.h>

    int main()
    {

    float weeklysale, salary1, salary2, salary3, salary4, rate;
    int id, paycode, hours, itemsproduced;

    printf( "\nEnter employee's ID number (-1 to end): ");
    scanf( "%d", &id );

    if ( id > 99 ) {
    printf ("Wrong ID Number. Please enter a new one (2 digits max.): ");
    scanf( "%d", &id );

    while ( id != -1 ) {
    printf( "\nSelect a Paycode:\n1 is for managers\n2 is for commission workers\n" );
    printf( "3 is for hourly workers\n4 is for pieceworkers\n\n" );
    printf( "Enter chosen Paycode: ");
    scanf( "%d", &paycode );



    while ( paycode = getchar() ) {

    switch ( paycode ) {

    case '1':
    paycode = 1;
    break;

    case '2':
    paycode = 2;
    break;

    case '3':
    paycode = 3;
    break;

    case '4':
    paycode = 4;
    break;

    case '\n':
    break;

    default:
    printf( "Incorrect Paycode number entered. " );
    printf( "Enter new Paycode number:\n" );
    break;
    }
    }
    }

    if ( paycode == 1 )
    salary1 = 2500.00;
    printf( "Salary is $%.2f\n\n\n", salary1 );

    if ( paycode == 2 ){
    printf( "Enter # of hours worked: " );
    scanf( "%d", &hours );

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

    if ( hours <= 40 )
    salary2 = hours * rate;

    if ( hours > 40 )
    salary2 = ( float ) (hours - 40) * (1.50 * rate) + (40 * rate);

    printf( "Salary is $%.2f\n\n\n", salary2 );
    }
    if ( paycode == 3 ) {
    printf( "Enter gross weekly sales of the worker ($00.O0): ");
    scanf( "%f", &weeklysale );

    salary3 = 250.00 + ( 6.5 * weeklysale ) / 100;
    printf( "Salary is $%.2f\n\n\n", salary3 );
    }
    if ( paycode == 4 ) {
    printf( "Enter # of items produced by the worker: ");
    scanf( "%d", &itemsproduced );

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

    salary4 = itemsproduced * rate;
    printf( "Salary is $%.2f\n\n\n", salary4 );
    }
    }
    return 0;
    }

  2. #2
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Hi!

    First you read in paycode using
    scanf( "%d", &paycode );
    and then overwrite it with the result of getchar.

    Just use something like this instead of your while-loop:
    Code:
    do
    {
       printf("Enter paycode: ");
       scanf("%d", &paycode);
    }
    while(paycode>0 && paycode<5);
    alex

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 11:58 PM
  2. Salary Range Calculator help please!! =(
    By bambino in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2006, 07:17 PM
  3. finally my salary program but...........
    By pancho in forum C Programming
    Replies: 11
    Last Post: 02-02-2002, 11:28 PM
  4. salary program heeeelp!
    By pancho in forum C Programming
    Replies: 6
    Last Post: 02-02-2002, 08:56 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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