Errors in programming code

I need to know why my error messages are saying:

'principalAmount' cannot be used as a function
assignment of read-only variable 'debtincomePercentage'

Any help or guidance would be amazing!


#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
// Declare Variables
const double interestRate = .05;
const double debtincomePercentage = .28;

const int loanTerm = 20;

char answer1,answer2,answer3;

double houseCost, downPayment, principalAmount, annualIncome, monthlyDebt, downpayPercent, insurancePrice;
double insuranceRate, countyTax;
double compoundTotal;

// Calculate totals
cout << "How much does the house cost?" << endl;
cin >> houseCost;

cout << "How much are you putting down on the house?" << endl;
cin >> downPayment;

downpayPercent = downPayment / houseCost;
principalAmount = houseCost - downPayment;

if (downpayPercent < 0.20)
{
cout << "Since down payment is less then 20% of home price, the private mortgage insurance will be required at 1% of total loan amount." << endl;
insurancePrice = principalAmount * 0.01;
}

cout << "Do you live in Mecklenburg County? (y or n)" << endl;
cin >> answer1;

cout << "Are you active military? (y or no) "<< endl;
cin >> answer2;

cout << "Are you 65 or older? (y or n)" << endl;
cin >> answer3;

if (answer1 == 'n' && answer2 == 'y' || answer3 == 'y')
countyTax = 0.01;
else
if (answer1 == 'n' && answer2 == 'n' || answer3 == 'n')
countyTax = 0.012;
else
if ( answer1 == 'y')
countyTax = 0.015;

// Input from user
cout << "What is your annual income?" << endl;
cin >> annualIncome;

cout << "How much do you pay monthly for debts?" << endl;
cin >> monthlyDebt;

// Calculations
compoundTotal = principalAmnt (pow((1+interestRate),loanTerm));
debtincomePercentage = (compoundTotal + monthlyDebt) / (annualIncome / 12);

if (debtincomePercentage < 0.28)
{
cout << "Decisioned as approved!" << endl;
cout << "Your debt to income ratio is:" << debtincomePercentage << endl;
}

else
{
cout << "Decision as declined." << endl;
cout << "Your debt to income ratio is:" << debtincomePercentage << endl;
}

return 0;
}
principalAmnt(pow((1 + interestRate), loanTerm))
principalAmnt is not a function, the way you have it written your compiler thinks it is.

const double debtincomePercentage = .28;

debtincomePercentage = (compoundTotal + monthlyDebt) / (annualIncome / 12);
debtincomePercentage is a const and not modifiable because it is const.
Last edited on
I guess I really don't understand what that means... How can I make it a function?
Please use code tags: http://www.cplusplus.com/forum/articles/42672/

if that's the error message you recieved, that is perplexing.

However, a quick paste of your code into my IDE gives me an error on the line immediately following // Calculations
compoundTotal = principalAmnt (pow((1+interestRate),loanTerm));
principanAmnt is undefined.

and the line immediately following that you're trying to assign a value to debtincomePercentage, which is defined as const, and thus cannot be modified and gives an error if you try.
I am going out on a limb to say you do not want to make a function but instead you want to do some math operation. In that case you need to change the formatting of this line.

compoundTotal = principalAmount(pow((1 + interestRate), loanTerm));

to something like

compoundTotal = principalAmountsome operator *-+/(pow((1 + interestRate), loanTerm));
Last edited on
Thanks so much! That worked! I can't believe I forgot the multiplication sign.
Topic archived. No new replies allowed.