Compile Errors in Programming Assignment

I'm stuck on an assignment. For some reason, I keep getting compile errors. The project I'm working on will ask a user for information about their budget and display a report on the information gathered. I was hoping to attach files with my code to this post, but it doesn't look like that's possible, so I'll put it in the body of my message.
Code so far:
/***********************************************************************
* Program:
* Project 03, Monthly Budget
* Brother Honeycutt, CS124
* Author:
* Lanie Molinar
* Summary:
* This program will prompt a user for his or her monthly budget and then
* display it on the screen.
*
* Estimated: 6.0 hrs
* Actual: 10.0 hrs
* It was difficult to remember everything, and at one point, I forgot to
* write out the computeTax function and just have it return 0, so there was a
* missing piece and I couldn't figure out what it was.
************************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;

/**********************************************************************
* The main function tells a program where to start.
***********************************************************************/

/******************************************************************************
* This function prompts the user for their income and then stores the
* information.
******************************************************************************/
float getIncome()
{
float income;
cout << "\tYour monthly income: ";
cin >> income;
return income;
}

/******************************************************************************
* This function prompts the user for their budgeted living expenses and then
* stores the information.
******************************************************************************/
float getBudgetLiving()
{
float budgetLiving;
cout << "\tYour budgeted living expenses: ";
cin >> budgetLiving;
return budgetLiving;
}

/******************************************************************************
* This function prompts the user for their actual living expenses and then
* stores the information.
******************************************************************************/
float getActualLiving()
{
float actualLiving;
cout << "\tYour actual living expenses: ";
cin >> actualLiving;
return actualLiving;
}

/******************************************************************************
* Right now, this function only returns 0.00 for budgeted taxes. Later, it will
* compute the budgeted tax amount.
******************************************************************************/
float computeTax(income)
{
float budgetTax = 0.00;
return budgetTax;
}

/******************************************************************************
* This function prompts the user for the amount of taxes they paid and then
stores the information.
******************************************************************************/
float getActualTax()
{
float actualTax;
cout << "\tYour actual taxes withheld: ";
cin >> actualTax;
return actualTax;
}

/******************************************************************************
* This function prompts the user for their tithing and then stores the
* information.
******************************************************************************/
float getActualTithing()
{
float actualTithing;
cout << "\tYour actual tithe offerings: ";
cin >> actualTithing;
return actualTithing;
}

/******************************************************************************
* This function prompts the user for their other expenses and then stores the
* information.
******************************************************************************/
float getActualOther()
{
float actualOther;
cout << "\tYour actual other expenses: ";
cin >> actualOther;
return actualOther;
}

/******************************************************************************
* This function computes the tithing a person should pay based on income and
* then stores the information.
******************************************************************************/
float computeTithing(income)
{
return income / 10;
}

/******************************************************************************
* This function displays the expense report.
******************************************************************************/
void display(income, budgetLiving, budgetTax, actualTax, budgetTithing,
actualTithing, actualLiving, actualOther)
{
cout << "The following is a report on your monthly expenses\n";
cout << "\tItem" << setw(24) << "Budget" << setw(17) << "Actual\n";
cout << "\t=============== =============== ===============\n";
cout << "\tIncome" << setw(11) << "$" << setw(11) << income
<< setw(5) << "$" << setw(11) << income << endl;
cout << "\tTaxes" << setw(12) << "$" << setw(11) << 0.00 << setw(5) << "$"
<< setw(11) << actualTax << endl;
cout << "\tTithing" << setw(10) << "$" << setw(11) << computeTithing(float
income) << setw(5) << "$" << setw(11) << actualTithing << endl;
cout << "\tLiving" << setw(11) << "$" << setw(11) << budgetLiving << setw(5)
<< "$" << setw(11) << actualLiving; cout << endl;
cout << "\tOther" << setw(12) << "$" << setw(11) << income - budgetTax
- budgetTithing - budgetLiving << setw(5) << "$" << setw(11) <<
actualOther << endl;
cout << "\t=============== =============== ===============\n";
cout << "\tDifference" << setw(7) << "$" << setw(11) << 0.00 << setw(5)
<< "$" << setw(11) << income - actualTax - actualTithing -
actualLiving - actualOther << endl;
return;
}

/******************************************************************************
* Main() calls the other functions.
******************************************************************************/
int main()
{
cout << "This program keeps track of your monthly budget\nPlease enter the following:\n";

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
float income = getIncome();
float budgetLiving = getBudgetLiving();
float actualLiving = getActualLiving();
float budgetTax = computeTax();
float actualTax = getActualTax();
float budgetTithing = computeTithing();
float actualTithing = getActualTithing();
float actualOther = getActualOther();;

getIncome();
getBudgetLiving();
getActualLiving();
getActualTax();
getActualTithing();
getActualOther();
cout << endl;

display();
}

I would really appreciate it if someone could look at this as soon as possible and help me understand what I'm doing wrong. Please let me know if you need more information, such as the written assignment description or the file with the compile errors. I wanted to paste them here but I'm having trouble getting them to fit. Thanks.
You need to specify the type of each parameter.

 
float computeTax(float income)
I fixed the problems I think you were talking about, but I'm still getting errors.
Revised code:
/***********************************************************************
* Program:
* Project 03, Monthly Budget
* Brother Honeycutt, CS124
* Author:
* Lanie Molinar
* Summary:
* This program will prompt a user for his or her monthly budget and then
* display it on the screen.
*
* Estimated: 6.0 hrs
* Actual: 10.0 hrs
* It was difficult to remember everything, and at one point, I forgot to
* write out the computeTax function and just have it return 0, so there was a
* missing piece and I couldn't figure out what it was.
************************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;

/**********************************************************************
* The main function tells a program where to start.
***********************************************************************/

/******************************************************************************
* This function prompts the user for their income and then stores the
* information.
******************************************************************************/
float getIncome()
{
float income;
cout << "\tYour monthly income: ";
cin >> income;
return income;
}

/******************************************************************************
* This function prompts the user for their budgeted living expenses and then
* stores the information.
******************************************************************************/
float getBudgetLiving()
{
float budgetLiving;
cout << "\tYour budgeted living expenses: ";
cin >> budgetLiving;
return budgetLiving;
}

/******************************************************************************
* This function prompts the user for their actual living expenses and then
* stores the information.
******************************************************************************/
float getActualLiving()
{
float actualLiving;
cout << "\tYour actual living expenses: ";
cin >> actualLiving;
return actualLiving;
}

/******************************************************************************
* Right now, this function only returns 0.00 for budgeted taxes. Later, it will
* compute the budgeted tax amount.
******************************************************************************/
float computeTax(float income)
{
float budgetTax = 0.00;
return budgetTax;
}

/******************************************************************************
* This function prompts the user for the amount of taxes they paid and then
stores the information.
******************************************************************************/
float getActualTax()
{
float actualTax;
cout << "\tYour actual taxes withheld: ";
cin >> actualTax;
return actualTax;
}

/******************************************************************************
* This function prompts the user for their tithing and then stores the
* information.
******************************************************************************/
float getActualTithing()
{
float actualTithing;
cout << "\tYour actual tithe offerings: ";
cin >> actualTithing;
return actualTithing;
}

/******************************************************************************
* This function prompts the user for their other expenses and then stores the
* information.
******************************************************************************/
float getActualOther()
{
float actualOther;
cout << "\tYour actual other expenses: ";
cin >> actualOther;
return actualOther;
}

/******************************************************************************
* This function computes the tithing a person should pay based on income and
* then stores the information.
******************************************************************************/
float computeTithing(float income)
{
return income / 10;
}

/******************************************************************************
* This function displays the expense report.
******************************************************************************/
void display(float income, float budgetLiving, float budgetTax, float
actualTax, floatbudgetTithing, float actualTithing, float actualLiving,
float actualOther)
{
cout << "The following is a report on your monthly expenses\n";
cout << "\tItem" << setw(24) << "Budget" << setw(17) << "Actual\n";
cout << "\t=============== =============== ===============\n";
cout << "\tIncome" << setw(11) << "$" << setw(11) << income
<< setw(5) << "$" << setw(11) << income << endl;
cout << "\tTaxes" << setw(12) << "$" << setw(11) << 0.00 << setw(5) << "$"
<< setw(11) << actualTax << endl;
cout << "\tTithing" << setw(10) << "$" << setw(11) << computeTithing(float
income) << setw(5) << "$" << setw(11) << actualTithing << endl;
cout << "\tLiving" << setw(11) << "$" << setw(11) << budgetLiving << setw(5)
<< "$" << setw(11) << actualLiving; cout << endl;
cout << "\tOther" << setw(12) << "$" << setw(11) << income - budgetTax
- budgetTithing - budgetLiving << setw(5) << "$" << setw(11) <<
actualOther << endl;
cout << "\t=============== =============== ===============\n";
cout << "\tDifference" << setw(7) << "$" << setw(11) << 0.00 << setw(5)
<< "$" << setw(11) << income - actualTax - actualTithing -
actualLiving - actualOther << endl;
return;
}

/******************************************************************************
* Main() calls the other functions.
******************************************************************************/
int main()
{
cout << "This program keeps track of your monthly budget\nPlease enter the following:\n";

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
float income = getIncome();
float budgetLiving = getBudgetLiving();
float actualLiving = getActualLiving();
float budgetTax = computeTax();
float actualTax = getActualTax();
float budgetTithing = computeTithing();
float actualTithing = getActualTithing();
float actualOther = getActualOther();;

getIncome();
getBudgetLiving();
getActualLiving();
getActualTax();
getActualTithing();
getActualOther();
cout << endl;

display();
}
1
2
3
floatbudgetTithing
     ^
     You need a space here.


1
2
3
computeTithing(float income) 
                 ^
                 You should not mention the type when calling the function.


1
2
3
4
5
6
7
8
9
10
float income = getIncome();
float budgetLiving = getBudgetLiving();
float actualLiving = getActualLiving();
float budgetTax = computeTax( You forgot to pass the income as argument );
float actualTax = getActualTax();
float budgetTithing = computeTithing( You forgot to pass the income as argument );
float actualTithing = getActualTithing();
float actualOther = getActualOther();

display( You need to pass all above variables as argument here, in the correct order );
Last edited on
Does this look any better? I'm still getting errors.

/***********************************************************************
* Program:
* Project 03, Monthly Budget
* Brother Honeycutt, CS124
* Author:
* Lanie Molinar
* Summary:
* This program will prompt a user for his or her monthly budget and then
* display it on the screen.
*
* Estimated: 6.0 hrs
* Actual: 10.0 hrs
* It was difficult to remember everything, and at one point, I forgot to
* write out the computeTax function and just have it return 0, so there was a
* missing piece and I couldn't figure out what it was.
************************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;

/**********************************************************************
* The main function tells a program where to start.
***********************************************************************/

/******************************************************************************
* This function prompts the user for their income and then stores the
* information.
******************************************************************************/
float getIncome()
{
float income;
cout << "\tYour monthly income: ";
cin >> income;
return income;
}

/******************************************************************************
* This function prompts the user for their budgeted living expenses and then
* stores the information.
******************************************************************************/
float getBudgetLiving()
{
float budgetLiving;
cout << "\tYour budgeted living expenses: ";
cin >> budgetLiving;
return budgetLiving;
}

/******************************************************************************
* This function prompts the user for their actual living expenses and then
* stores the information.
******************************************************************************/
float getActualLiving()
{
float actualLiving;
cout << "\tYour actual living expenses: ";
cin >> actualLiving;
return actualLiving;
}

/******************************************************************************
* Right now, this function only returns 0.00 for budgeted taxes. Later, it will
* compute the budgeted tax amount.
******************************************************************************/
float computeTax(float income)
{
float budgetTax = 0.00;
return budgetTax;
}

/******************************************************************************
* This function prompts the user for the amount of taxes they paid and then
stores the information.
******************************************************************************/
float getActualTax()
{
float actualTax;
cout << "\tYour actual taxes withheld: ";
cin >> actualTax;
return actualTax;
}

/******************************************************************************
* This function computes the tithing a person should pay based on income and
* then stores the information.
******************************************************************************/
float computeTithing(float income)
{
return income / 10;
}

/******************************************************************************
* This function prompts the user for their tithing and then stores the
* information.
******************************************************************************/
float getActualTithing()
{
float actualTithing;
cout << "\tYour actual tithe offerings: ";
cin >> actualTithing;
return actualTithing;
}

/******************************************************************************
* This function prompts the user for their other expenses and then stores the
* information.
******************************************************************************/
float getActualOther()
{
float actualOther;
cout << "\tYour actual other expenses: ";
cin >> actualOther;
return actualOther;
}

/******************************************************************************
* This function displays the expense report.
******************************************************************************/
void display(float income, float actualLiving, float budgetLiving, float
budgetTax, float actualTax, float budgetTithing, float actualTithing,
float actualOther)
{
cout << "The following is a report on your monthly expenses\n";
cout << "\tItem" << setw(24) << "Budget" << setw(17) << "Actual\n";
cout << "\t=============== =============== ===============\n";
cout << "\tIncome" << setw(11) << "$" << setw(11) << income
<< setw(5) << "$" << setw(11) << income << endl;
cout << "\tTaxes" << setw(12) << "$" << setw(11) << 0.00 << setw(5) << "$"
<< setw(11) << actualTax << endl;
cout << "\tTithing" << setw(10) << "$" << setw(11) << computeTithing()
<< setw(5) << "$" << setw(11) << actualTithing << endl;
cout << "\tLiving" << setw(11) << "$" << setw(11) << budgetLiving << setw(5)
<< "$" << setw(11) << actualLiving; cout << endl;
cout << "\tOther" << setw(12) << "$" << setw(11) << income - budgetTax
- budgetTithing - budgetLiving << setw(5) << "$" << setw(11) <<
actualOther << endl;
cout << "\t=============== =============== ===============\n";
cout << "\tDifference" << setw(7) << "$" << setw(11) << 0.00 << setw(5)
<< "$" << setw(11) << income - actualTax - actualTithing -
actualLiving - actualOther << endl;
return;
}

/******************************************************************************
* Main() calls the other functions.
******************************************************************************/
int main()
{
cout << "This program keeps track of your monthly budget\nPlease enter the following:\n";

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
float income = getIncome();
float budgetLiving = getBudgetLiving();
float actualLiving = getActualLiving();
float budgetTax = computeTax();
float actualTax = getActualTax();
float budgetTithing = computeTithing();
float actualTithing = getActualTithing();
float actualOther = getActualOther();;

getIncome();
getBudgetLiving();
getActualLiving();
getActualTax();
getActualTithing();
getActualOther();
cout << endl;

display();
}
Check the last bit Peter87 mentioned above. If you've defined a function to take one or more arguments, you need to make sure when you call the function that those arguments are sent.

Also - in the display function, the code is calling the computeTithing function - did you mean this to be the value of one of the arguments sent in?

cout << "\tTithing" << setw(10) << "$" << setw(11) << computeTithing()

One last thing - the code is actually calling the set of functions twice: once in the declarations of all the variables, then again after the variables are declared. I think you mean to prompt the user only once for all the info.
That helps a lot. How do I avoid calling a function twice? I know I need to declare the variables, so I can't get rid of that. If I get rid of the part below, am I still calling the functions, and am I calling them in the right spot?

getIncome();
getBudgetLiving();
getActualLiving();
getActualTax();
getActualTithing();
getActualOther();
cout << endl;
you don't have to invoke functions to declare variables.

just say

int x;
double d;

...

foo(x);
bar(d);

float income = getIncome(); ///calls your function
make this just
float income;
or float income = 0; //some people initialize everything.


Hmm, okay. I'm getting different information from different people. I worked with a tutor at my school a couple weeks ago, and he was the one who told me to write things like float income = getIncome(). His method doesn't seem to be working though, so I'll try this.
In this part, you are calling the functions, but not doing anything with the value they return.

1
2
3
4
5
6
7
getIncome();
getBudgetLiving();
getActualLiving();
getActualTax();
getActualTithing();
getActualOther();
cout << endl; 


So if you do change to declare the variable without immediately assigning a value, e.g.

float income;

then the later call to the function can change so it saves the value returned.

income = getIncome();
you can do it many ways. There is no conflicting info, it comes down to your needs in the given program what format you want here. Your tutor probably has one set of assumptions, and I had another.

int x; //created, has random value
int x = 0; //created, is zero.

int x = foo(42); //x is whatever the function returns.

foo(x);// call foo with x's value. If foo returns a value, it is lost, and sometimes that is OK!

all that is legal and each has a purpose in C++.

But back to your issue, you call the functions twice, once to assign into a variable, and again below without assigning it. Just looking at the code, you need one or the other, not both!

Topic archived. No new replies allowed.