Thread: need help

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    need help

    It is obvious that I am new to c++, AnyWay Im combining two projects into one. I have questions about Switch structures, and nesting them with an if/else structure.

    My program should compute employess weekly pay. Mangers have payCode1, hourlyWorkers payCode2, comissionWorkers payCode3, and pieceWorkers have payCode4; Mangers have a fixed income for (hours<=40) and hours(<40) gets paid 1.5"time and a half".
    ComissionWorker get paid 250.00+5.7% of gross weeklysales, and pieceWorkers get paid fixed amount of money per items produce. Now I already have my program outputting my pay based on hours and overtime hours. Im haveing problems using a switch structure to give me pay based on paycode.

    Here is what I have so for, please help me in this peaceful journey;

    # include<stdio.h>
    int main(void);{

    int hours;
    double rate, pay;
    hours=0;

    while(hours!=-1){
    printf("hours(-1 to end):");
    scanf("%d",&hours);

    if(hours!=-1){
    printf("rate");
    scanf("%d",&rate);
    if(hours>40){
    pay= (40 * rate + ((hours - 40 * rate * 1.5)));
    }
    else
    pay=hours*rate;
    printf("gross pay is%f", grosspay);
    }
    }
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    im not great with the whole printf scanf business so just convert my cout cins

    Code:
    cout << "Enter employee pay code: ";
    cin >> int code;
    
    switch (code)
    {
    case 1:              //insert code for paycode 1
                             break;
    
    case 2:             //insert code for paycode 2
                            break;
    
    case 3:            //insert code for paycode 3
                           break;
    
    case 4:            //insert code for paycode 4
                           break;
    
    default:           //insert code if they input something else besides 1-4
                           break;
    }
    Last edited by Jamsan; 02-27-2003 at 06:06 PM.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    Originally posted by Jamsan
    im not great with the whole printf scanf business so just convert my cout cins

    Code:
    cout << "Enter employee pay code: ";
    cin >> int code;
    
    switch (code)
    {
    case 1:              //insert code for paycode 1
                             break;
    
    case 2:             //insert code for paycode 2
                            break;
    
    case 3:            //insert code for paycode 3
                           break;
    
    case 4:            //insert code for paycode 4
                           break;
    
    default:           //insert code if they input something else besides 1-4
                           break;
    }
    Spacing is a little weird... otherwise thats right

    Code:
    switch(variable)
    {
          case (number or SINGLE character) // this is like the variable == blank
                //code to run if this is true
                break;
          case (number or SINGLE character)
                //code to run if this is true
                break;
          default:      //if none of the case statements above were true, then this is run
                //code to run if no other case is true
                break;
    }
    Please use code tags: [ code ] and [ /code ] without the spaces

    Also, you cannot run comparisons in a switch, its really just an == kind of thing.
    Last edited by Trauts; 02-27-2003 at 06:24 PM.

Popular pages Recent additions subscribe to a feed