Help

So I had started this off wrong and will go back to delete my first post. The assignment states:

In Lab 10 you were asked to write a 4-function program to calculate child tax credit. A family can claim $1000 tax credit per child, but the total child tax credit cannot exceed $4000 if the family income exceeds $70,000. In other words, families with income more than $70,000 can claim $4000 child tax credit at the most, but families with income $70,000 or less can claim more than $4000 child tax credit if there are more than 4 children ($1000 credit per child). The four functions we used were:

getnumChildren: a value-returning function that asks for the number of children and uses a return statement to send it to main.

getIncome: a value-returning function that asks for the family income and uses a return statement to send it to main.

calcCredit: a value-returning function that calculates and returns child tax credit to main.

main: a function that invokes the other three functions and displays the total tax credit on the computer screen.

Modify the program you wrote last time as follows. Replace the getnumChildren and getIncome functions by one function getChiAndIncome, which gets both the number of children and family income from the user. Use pass-by-reference to pass these two items to main.

Original Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Lab01005.cpp – Calculate child tax credit with 4 functions using an income stipulation
// Created by Taft Sanders on 10/19/2012
#include <iostream>

using namespace std;

int getNumChildren();
double calCredit(int,int);
int getIncome ();

int main( )
{
   int numChildren = 0;
   double totCredit = 0.0;
   int income=0;

   numChildren = getNumChildren();

   income = getIncome();

   totCredit = calCredit(numChildren, income);

   system("pause");
   return 0;
}

int getNumChildren()
{
   int numChi = 0;
   cout <<"How many children do you have? ";
   cin >> numChi;
   return numChi;
}

double calCredit (int numChi, int income)
{
   double credit = 0;
   int taxCredit=0;

  if (income <= 70000)
   {
       taxCredit= numChi * 1000;
       cout<< "Total tax credit: "<<taxCredit<<endl;
   }

   else if (income>70000)
   {
       if (numChi>=4)
       {
           cout<<"Total tax credit: 4000"<<endl;
       }
       else if (numChi<4)
       {
           taxCredit=numChi*1000;
           cout<< "Total tax credit: "<<taxCredit<<endl;
       }
   }


   return credit;
}

int getIncome ()
{
    int worth=0;

    cout<< "What is your income: ";
    cin>>worth;
    return worth;
}


New Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Lab01005.cpp – Calculate child tax credit with 4 functions using an income stipulation
// Created by Taft Sanders on 10/19/2012
#include <iostream>

using namespace std;

int getChiAndIncome();
double calCredit(int,int);

int main( )
{
   double totCredit = 0.0;

   getChiAndIncome();

   totCredit = calCredit(int getChiAndIncome);

   system("pause");
   return 0;
}

int getChiAndIncome()
{
   int numChi = 0;
   int worth=0;

   cout<< "What is your income: ";
   cin>>worth;
   return worth;

   cout <<"How many children do you have? ";
   cin >> numChi;
   return numChi;
}

double calCredit (int numChi, int income)
{
   double credit = 0;
   int taxCredit=0;

  if (income <= 70000)
   {
       taxCredit= numChi * 1000;
       cout<< "Total tax credit: "<<taxCredit<<endl;
   }

   else if (income>70000)
   {
       if (numChi>=4)
       {
           cout<<"Total tax credit: 4000"<<endl;
       }
       else if (numChi<4)
       {
           taxCredit=numChi*1000;
           cout<< "Total tax credit: "<<taxCredit<<endl;
       }
   }


   return credit;
}


Ending with an error:
C:\Users\Showdon\Desktop\C++\Lab11\main.cpp|16|error: expected primary-expression before "int"|
On line 16, what are you trying to do? It looks like you are trying to call calCredit() but you aren't passing enough parameters and aren't passing the one correctly anyway.
I have to merge the numChildren and getIncome function into 1 function called getChiAndIncome then use pass by reference to pass both those values to main.
Topic archived. No new replies allowed.