Need some advice

This is a discussion on Need some advice within the C++ Programming forums, part of the General Programming Boards category; Hey guys I need to combine the following into one if statement: else if (hrs >= 40.01) { salary = ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Unhappy Need some advice

    Hey guys I need to combine the following into one if statement:

    else if (hrs >= 40.01)
    {
    salary = hrs * payrt * 1.5;
    cout << "\nYour gross pay for the week is " << setw(1) << ":"
    << setw(8) << salary << endl;
    }

    else if (hrs <= 59.99)
    {
    salary = hrs * payrt * 1.5;
    cout << "\nYour gross pay for the week is " << setw(1) << ":"
    << setw(8) << salary << endl;
    }

    I tried: else if (hrs >= 40.01 || <= 59.99) but it didnt work. Thanx for your help.

    N.B. this is just part of my program, I also found the hours worked over 60 hrs and hours worked under 40 hrs. This is only part that goes crazy once its ran, so I am trying to combine the two if statements.

  2. #2
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    >else if (hrs >= 40.01 || <= 59.99)
    That won't work, what are you testing the second condition on? You assumed it would test the condition on hrs, but in this game you can't assume anything or you'll get burned
    Code:
    else if ( hrs >= 40.01 || hrs <= 59.99 ) {
        .
        .  // Do stuff
        .
    }
    BTW, combining the two statements will perform exactly the same, so your "going crazy" could very well be caused by something else. Though repetition is bad in coding and using one test to do the same thing instead of two tests will save you heartache in debugging.
    pointer = NULL

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    Re: Need some advice

    Originally posted by taurusborn
    Hey guys I need to combine the following into one if statement:

    else if (hrs >= 40.01)
    {
    salary = hrs * payrt * 1.5;
    cout << "\nYour gross pay for the week is " << setw(1) << ":"
    << setw(8) << salary << endl;
    }

    else if (hrs <= 59.99)
    {
    salary = hrs * payrt * 1.5;
    cout << "\nYour gross pay for the week is " << setw(1) << ":"
    << setw(8) << salary << endl;
    }

    Maybe try:
    else if (hrs > 40 && hrs < 60)
    {
    .
    .
    .
    }

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Thanx

    Thanx a million guys, my program now works, you guys rock!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice on C Programming with MSVC++ 2008
    By IT_Guy in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2009, 03:23 AM
  2. Advice on multithreading
    By Calef13 in forum C++ Programming
    Replies: 3
    Last Post: 08-24-2007, 03:28 PM
  3. girl friend advice (prob. the wrong place)
    By B0bDole in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2004, 06:38 PM
  4. need advice on project
    By lambs4 in forum C Programming
    Replies: 2
    Last Post: 07-23-2003, 01:06 PM
  5. Who's telling the truth??? Career Advice Needed Badly
    By Ican'tCjax,fl in forum C Programming
    Replies: 1
    Last Post: 11-06-2002, 05:16 PM

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