Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C++ mini question

  • 25-11-2005 08: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