Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ mini question

  • 25-11-2005 7:56pm
    #1
    Closed Accounts Posts: 1,299 ✭✭✭


    Hello I need a bit of help with a programme I basically have to assign a value for tax, which I have done here
    tax = (.2*200) + (.4*hightax_pay) - tax_credits;

    which is working perfect except I need another bit which says it can never be negative, as in in the instance where tax credits exceed tax,
    so what should I enter


Comments

  • Registered Users, Registered Users 2 Posts: 19,396 ✭✭✭✭Karoma


    Being totally honest, I'm not giving this too much thought but the first thing that comes to mind:

    Store the (.2*200) + (.4*hightax_pay) calculation as a variable {a}; and do a comparison to tax_credits {b} before you do the total tax calculation.
    ie.
    pseudo-code:
    if(a < b) 
    { 
      // i.e. {b} = tax credits, and exceeds {a} - exit gracefully
      // exception handling
    }
    else 
    {
      // otherwise, the calculation applies as normal..
      a - b;
    }
    


  • Closed Accounts Posts: 1,299 ✭✭✭Sandals


    Yes thanks my mind just drew a blank thats perfect, also one final question I have to output four variables at the end of the program on the one line with spaces, how do I do that, eg.
    cout << employee_no << gross_pay << net_pay << tax;


  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    cout << "your wages are " << wages << " and you pay tax of " << tax << endl;

    should work


  • Closed Accounts Posts: 1,299 ✭✭✭Sandals


    No I can't have any text, just the figures that's the problem, its an assignment for college.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Sandals wrote:
    No I can't have any text, just the figures that's the problem, its an assignment for college.
    Then delete the text...

    cout << " " << wages << " " << tax << endl;


  • Advertisement
  • Closed Accounts Posts: 1,299 ✭✭✭Sandals


    Then delete the text...

    cout << " " << wages << " " << tax << endl;


    Your The man.


Advertisement