Thread: Keep getting negative sign after answer

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    4

    Keep getting negative sign after answer

    Hello all,

    I am trying to get this program to work but all I keep getting is negative signs after the correct answers. Can someone please help me figure this out?

    I am trying to just get the correct answers without the negative signs.

    Thank you in advance

    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    using namespace std;
    
    const double TaxRate= .14;
    const double MyBond= .25;
    const double ParentBond= .50;
    
    int main()
    
    {
        //declaration section
        double Gross, PSB, MSB, RemainingBalance, PayRate, NetIncome, FinalTotal, CExpense, SExpense, TaxWithheld, HoursWork, Week= 5;
        cout<<fixed<<showpoint;
        cout.precision(2);
        
        //input section
        cout<<"Please enter your pay rate"<<endl;
        cin>>PayRate;
        cout<<"Please enter the number of hours you worked each week"<<endl;
        cin>>HoursWork;
        
        //computation section
        Gross= Week*HoursWork*PayRate;
        TaxWithheld= Gross*TaxRate;
        NetIncome= TaxWithheld-Gross;
        CExpense= NetIncome*.10;
        SExpense= NetIncome*.01;
        RemainingBalance= CExpense+SExpense-NetIncome;
        MSB=RemainingBalance*MyBond;
        PSB=MSB*ParentBond;
        FinalTotal= MSB-RemainingBalance;
        
        //output section
        cout<<"After working 5 weeks, you have Grossed: "<<Gross<<endl;
        cout<<"Taxes Withheld: "<<TaxWithheld<<endl;
        cout<<"Net Income: "<<NetIncome<<endl;
        cout<<"Clothing Expense: "<<CExpense<<endl;
        cout<<"Supplies Expense: "<<SExpense<<endl;
        cout<<"Remaining Balance after Taxes&Expenses: "<<RemainingBalance<<endl;
        cout<<"My Savings Bonds Contribution: "<<MSB<<endl;
        cout<<"Parents Savings Bonds Contribution: "<<PSB<<endl;
        cout<<"Final Total after Taxes, Expenses and Savings: "<<FinalTotal<<endl;
        
        system("PAUSE");
        return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to read more carefully:
    Code:
    NetIncome= TaxWithheld-Gross;

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    4
    Thanks, but it looks the same to me. Can you please tell me the difference? Sorry, if I'm not understanding.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Of course it looks the same, since I copied and pasted it directly from your code. You're supposed to read it and realize how error-ful it is.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    4
    Code:
    NetIncome=Gross-TaxWithheld;
    ?

  6. #6
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    You're obviously not an engineer. Instead of wasting your time trying to find the underlying cause of the problem, why don't you just multiply your final answer by -1?


    Please don't take anything I saw seriously. I just like to give engineers a hard time.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by uptown11 View Post
    Code:
    NetIncome=Gross-TaxWithheld;
    ?
    That is the version that corresponds with reality, yes.

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    4
    i figured it out...thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how would you answer this question?
    By smoking81 in forum Linux Programming
    Replies: 3
    Last Post: 09-08-2008, 03:53 AM
  2. random number between negative and positive number
    By anomaly in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2003, 08:40 AM
  3. Replies: 4
    Last Post: 10-29-2003, 01:18 PM
  4. getting weird answer when not using ".h"
    By CobraCC in forum C++ Programming
    Replies: 10
    Last Post: 05-07-2003, 06:21 AM
  5. Replies: 22
    Last Post: 11-08-2001, 11:01 PM