Functions - area and perimeter

I am writing a program to call the functions area and perimeter. This is what I have written but am still getting an error.

error C2064: term does not evaluate to a function taking 2 arguments

// Assignment4.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;


double area(double lengthA, double widthA);
double perimeter(double lengthP, double widthP);

int main()
{

double length;
double width;
double area;
double perimeter;

cout << "Enter the length of the rectangle: " ;
cin >> length;
cout << endl;

cout << "Enter the width of the rectangle: ";
cin >> width;
cout << endl;

cout << "The area of your rectangle is: " << area(length, width) << endl;

cout << "The perimeter of your rectangle is: " << perimeter(length, width) << endl;


system ("pause");

return 0;
}

double area(double lengthA, double widthA){

return lengthA * widthA;
}

int perimeter(int lengthP,int widthP){

return (lengthP * 2) + (widthP * 2);
}
Last edited on
The function declaration

double perimeter(double lengthP, double widthP);
does not correspond to the function definition

1
2
3
4
int perimeter(int lengthP,int widthP){
 
return (lengthP * 2) + (widthP * 2);
 } 
Try using different names for the functions and variables.
Also you named two variables such a way as the functions

double area;
double perimeter;


So the variable names hide functions.
Get rid of the declarations:

1
2
double area;
double perimeter;


These are declaring variables of those names, hiding the functions that you are trying to call. (I think that's what Peter87 is hinting at.)

Also, vlad is correct--you have type mismatches in your perimeter function. When you fix the first error, you will run into this one.

By the way, when you post code, please put it inside code tags. Click the "<>" button in the Format menu and past your code between the tags. I makes it easier to read, and it gives line numbers, making it easier to make comments about.
Thank you everyone. Sometimes you look at it for so long and your blurry. I removed the following variable:

double area;
double perimeter;


I also renamed my function perimeter's datatype from int - to - double, the same as it is in the prototype function before main and it ran beautifully.

Have a great day!!
Topic archived. No new replies allowed.