Help with program error

C++ Program help with error

Page 1 of 1

2 Replies - 789 Views - Last Post: 30 July 2010 - 10:15 PM Rate Topic: -----

#1 empills  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 10-July 10

Help with program error

Posted 30 July 2010 - 07:32 PM

I am writing a program that will calculate federal tax for the year. I am running into a problem with getting the yearly tax to display. For some reason it is coming up as 0.00. I am not sure which function is causing the error. Here is the code and thanks in advance for the help.
#include<iostream>
#include<iomanip>


using namespace std;

 void getData (char& maritalStatus, double& grossIncome, double& pensionAmount,
              int& children, int& numPeople, double& standardExemption, double& persExemption);
double taxAmount(int numPerson, double grossIncome, double pensionAmount, 
                 double persExemption, double standardExemption, double& totalTax);


int main()
{
    char maritalStatus;
    int children, numPerson;
    double taxableIncome, totalTax, grossIncome, pensionAmount;
    double standardExemption, persExemption, salary;
    
    
    totalTax = taxAmount(numPerson, salary, pensionAmount, persExemption,
                       standardExemption, totalTax);
    
    cout<<fixed << showpoint<<setprecision(2);
    cout<<"Your tax for the year is: $"<< totalTax <<endl;
    
    system("pause");
    return 0;
}

  void getData (char& maritalStatus, double& grossIncome, double& pensionAmount,
              int& children, int& numPerson, double& standardExemption, double& persExemption)
  {
      double taxableIncome;
      double pension;

      
      
        cout << "Enter marital status: m or M (married), s or S (single: ";
        cin >> maritalStatus;
        cout << endl;
        
          while(maritalStatus == 'm' || maritalStatus == 'M')
             {
              cout<< "Enter number of children under the age of 14: ";
              cin >> children;
              cout << endl;
              numPerson = 2 + children;
              standardExemption = 7000;
              break;
              }    
           
          while (maritalStatus =='s'||maritalStatus == 'S')
              {
              numPerson =1;
              standardExemption= 4000; 
              break;
          }     
          
          
          cout << "Enter gross Salary for the year: ";
          cin >> grossIncome;
          cout<<endl;
          
          cout << "Enter percentage of salary contributed to pension(0-6 percent): ";
          cin >> pension;
          cout << endl;
             pensionAmount = (pension/100)*grossIncome;
    persExemption= numPerson * 1500;
    taxableIncome= grossIncome-(pensionAmount + standardExemption + persExemption);
          
          }
      
double taxAmount(int numPerson, double grossIncome, double pensionAmount, 
                 double persExemption,double standardExemption,double& totalTax)
{
    double taxableIncome, marginalIncome, marginTax, pension;
    int tax;
    double baseTax;
    char maritalStatus;
    int children;
    double  salary;
    getData (maritalStatus, grossIncome, pensionAmount, children, numPerson,
             standardExemption, persExemption);
 
    
 if (taxableIncome <= 15000)
 {
  marginTax =.15 * taxableIncome;
  totalTax = marginTax;
 }
 else if (taxableIncome >= 15001 || taxableIncome <= 40000)
 {
  marginalIncome = taxableIncome - 15000;
  marginTax = .25 * taxableIncome;
  baseTax = 2250;
  totalTax = baseTax + marginTax;
 }
 else if (taxableIncome > 40000)
 {
  marginalIncome = taxableIncome - 40000;
  marginTax = .35 * taxableIncome;
  baseTax = 8460;
  totalTax = baseTax + marginTax;
 }
 return totalTax;
 
}
                    



Is This A Good Question/Topic? 0
  • +

Replies To: Help with program error

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1368
  • View blog
  • Posts: 4,737
  • Joined: 19-February 09

Re: Help with program error

Posted 30 July 2010 - 08:53 PM

The value taxableincome is not returned from getData(), the default value is taxableincome=0, so totalTax is 0.


It looks like getData() would be better called from main().
Was This Post Helpful? 1
  • +
  • -

#3 empills  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 10-July 10

Re: Help with program error

Posted 30 July 2010 - 10:15 PM

View Post#define, on 30 July 2010 - 07:53 PM, said:

The value taxableincome is not returned from getData(), the default value is taxableincome=0, so totalTax is 0.


It looks like getData() would be better called from main().


Thanks a lot for pointing me in the right direction.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1