(Before I ask my question, I have tried looking through google and the site already, and didn't find anything relevant to what my problem was. All I was finding was more complex than my current level.)

Anyway, my problem is that I'm getting an "expression must have (pointer-to-) function type error" in my code. I'm confused because I have never seen this type of error before.

Here's what I have so far. (I have pointed out where I have the error in the code.)

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;

const int MONTHS_PER_YEAR = 12; // Hard coding Number of Months in a Year

void PrintGreeting(); // Function Prototype for PrintGreeting()

int main ()
{
    float purchasePrice; // Declaring Purchase Price
    float amountDown; // Declaring Amount Down
    float annualInterestRate; // Declaring Annual Interest Rate
    int years; // Declaring Number of Years

    ifstream din; // Declaring Input File Variable
    ofstream dout; // Declaring Output File Variable

    float monthlyInterest; // Declaring Monthly Interest
    float monthlyPayment; // Declaring Monthly Payment

    PrintGreeting(); // Calls PrintGreeting

    din.open("vette.in"); // finding vette.in
    dout.open("vette.out"); // creating vette.out

    din >> purchasePrice >> amountDown >> annualInterestRate >> years; // inputting the values from an input file

    monthlyInterest = annualInterestRate / MONTHS_PER_YEAR; // finding the Monthly Interest

    monthlyPayment = monthlyInterest(purchasePrice - amountDown); // attempting to find the first part of the equation to find the Monthly Payment. This is the part of the code where I'm getting the error.


    return 0;
}

// =======================================================================

void PrintGreeting () 
{

/*
Purpose: Prints a nicely formatted greeting to the screen.
Pre: None.
Post: Greeting has been printed to the screen.
*/

cout << "\n\n\n\n\n";
cout << "Welcome to the EZ Speeeder \n";
cout << "This program is a Monthly Payment Calculator. \n";
cout << "Fall 2012 - Programmed by Zachary Daniels. \n";
cout << "\n\n\n\n\n";

}

The values from the input file are as follows:

The Purchase Price is 105670.00
The Amount Down is 12345
The Annual Interest Rate is 5.7
And the Number of Years is 4.

Can anybody help me figure out why it's giving me this error?

Recommended Answers

All 9 Replies

line 34: where is function monthlyInterest() prototyped?

Prototyped? I didn't think I needed to since I declared it on line 23.

line 23 declares a variable of type float named monthlyPayment, not a function named monthlyInterest().

Oops.. I meant line 22, not line 23; sorry.

Here you are declaring monthlyInterest as a float
float monthlyInterest

Here you are calling the function monthlyInterest, which does not exist. Its just a float as declared above.
monthlyPayment = monthlyInterest(purchasePrice - amountDown)

If you want monthlyInterest to be a function that calculates the interest you must create that function and remove the monthlyInterest float declaration.

float monthlyInterest( float someValue )
{
    // do your calcultation
    return 'the result'
}

Okay, so I have to create monthlyInterest as a function, and get rid of monthlyInterest as a float.

I believe I understand where I went wrong now.

Thanks, you two.

There is no float named monthlyInterest, maybe you are thinking monthlyInterestRate??

Like I said before, I delcared float monthlyInterest on line 22.

I changed my code a bit and the error seemed to have gone away.

All I had to do was change the code so that monthlyInterest was not a function, and simply a stand alone float.

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;

const int MONTHS_PER_YEAR = 12; // Hard coding Number of Months in a Year

void PrintGreeting(); // Function Prototype for PrintGreeting()

int main ()
{
    float purchasePrice; // Declaring Purchase Price
    float amountDown; // Declaring Amount Down
    float annualInterestRate; // Declaring Annual Interest Rate
    int years; // Declaring Number of Years

    ifstream din; // Declaring Input File Variable
    ofstream dout; // Declaring Output File Variable

    float monthlyInterest;
    float monthlyPaymentPartOne; // Declaring Monthly Payment (Part One of Two)
    float monthlyPaymentPartTwo; // Declaring Monthly Payment (Part Two of Two)
    float monthlyPaymentFull; // Declaring final Monthly Payment, bringing Part One and Part Two together. 

    PrintGreeting(); // Calls PrintGreeting

    din.open("vette.in"); // finding vette.in
    dout.open("vette.out"); // creating vette.out

    din >> purchasePrice >> amountDown >> annualInterestRate >> years; // inputting the values from an input value

    monthlyInterest = annualInterestRate / MONTHS_PER_YEAR; // finding the Monthly Interest

    monthlyPaymentPartOne = monthlyInterest * (purchasePrice - amountDown); // attempting to find the first part of the Monthly Payment equation. 

    return 0;

}

// ========================================================

void PrintGreeting () 
{

/*
Purpose: Prints a nicely formatted greeting to the screen.
Pre: None.
Post: Greeting has been printed to the screen.
*/

cout << "\n\n\n\n\n";
cout << "Welcome to the EZ Speeeder \n";
cout << "This program is a Monthly Payment Calculator. \n";
cout << "Fall 2012 - Programmed by Zachary Daniels. \n";
cout << "\n\n\n\n\n";

}

Thanks you two! You've been a huge help.

Yes, that seems to be the right code. now, don't you have to do something with that? Such as display it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.