Problem with a prototype function.

We are learning about prototype functions in my Programming for engineers class and just started prototype functions. I have already completed one program using a prototype function and used the same format to create this code but I can't get rid of six errors that indicate an unexpected double variable? I can change the variable to whatever and it still spits out an error. Here is what I have so far..
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
#include <iostream>
#include <cmath>
using namespace std;
 

double distance(int x1, int y1, int x2, int y2);
double radius(int x1, int y1, int x2, int y2);
double circumference(double radius);
double area(double radius);
 
int main()
{
int x1;
int x2;
int y1;
int y2;

cout<<"Enter a center point: ";
cin>>x1, y1;

cout<<"Enter a point on the circle: ";
cin>>x2, y2;


cout<<"The distance of the circle is: ";
cout<< distance(int x1, int y1, int x2, int y2);
cout<<endl;
 
cout<<"The area of the circle is: ";
cout<< area(double radius);
cout<<endl;
 
cout<<"The radius of the circle is: ";
cout<< radius(int x1, int y1, int x2, int y2);
cout<<endl;

cout<<"The circumference of the circle is: ";
cout<< circumference(double radius);
cout<<endl;

return 0;
}
 
double distance (int x1, int y1, int x2, int y2)
{
	int dx = x2 - x1;
	int dy = y2 - y1;
	double dsquared = dx*dx + dy*dy;
	double result = sqrt(dsquared);
	return result;
}
 
double radius (int x1, int y1, int x2, int y2)
{
	double radius = distance (x1, y1, x2, y2);
	double result = radius;
	return result;
}
 
double circumference(double radius)
{
	double circumference = 3.1416 * (radius * 2);
	return circumference;
}

double area(double radius)
{
	double area = 3.1416 * radius * radius;
	return area;
}


What am I doing wrong?
when you call the functions in main, dont include the type

example:

1
2
3
cout<<"The distance of the circle is: ";
cout<< distance(int x1, int y1, int x2, int y2);
cout<<endl;


should be
1
2
3
cout<<"The distance of the circle is: ";
cout<< distance(x1, y1, x2, y2);
cout<<endl;




also, as an afterthought, you can change your functions slightly to remove an unnecessary variable:

1
2
3
4
double area(double radius)
{
	return (3.1416 * radius * radius);
}


this will work for all of your functions
Last edited on
Okay that fixed that problem but now I am faced with a problem that I thought I had fixed by actually doing exactly what you told me not to do earlier, but after modifying the code it came back...
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
#include <iostream>
#include <cmath>
using namespace std;
 

double distance(int x1, int y1, int x2, int y2);
double radius(int x1, int y1, int x2, int y2);
double circumference(double radius);
double area(double radius);
 
int main()
{
int x1;
int x2;
int y1;
int y2;

cout<<"Enter a center point: ";
cin>>x1, y1;

cout<<"Enter a point on the circle: ";
cin>>x2, y2;


cout<<"The distance of the circle is: ";
cout<< distance(x1, y1, x2, y2);
cout<<endl;
 
cout<<"The area of the circle is: ";
cout<< area(radius);
cout<<endl;
 
cout<<"The radius of the circle is: ";
cout<< radius(x1, y1, x2, y2);
cout<<endl;

cout<<"The circumference of the circle is: ";
cout<< circumference(radius);
cout<<endl;

return 0;
}
 
double distance (int x1, int y1, int x2, int y2)
{
	int dx = x2 - x1;
	int dy = y2 - y1;
	double dsquared = dx*dx + dy*dy;
	double result = sqrt(dsquared);
	return result;
}
 
double radius (int x1, int y1, int x2, int y2)
{
	double radius = distance (x1, y1, x2, y2);
	double result = radius;
	return result;
}
 
double circumference(double radius)
{
	double circumference = 3.1416 * (radius * 2);
	return circumference;
}

double area(double radius)
{
	double area = 3.1416 * radius * radius;
	return area;
}


There is the code.

The output:
1>------ Build started: Project: Page358Number8, Configuration: Debug Win32 ------
1>Compiling...
1>Page358Number8.cpp
1>c:\users\willy\documents\visual studio 2008\projects\page358number8\page358number8\page358number8.cpp(30) : error C2664: 'area' : cannot convert parameter 1 from 'double (__cdecl *)(int,int,int,int)' to 'double'
1>        Context does not allow for disambiguation of overloaded function
1>c:\users\willy\documents\visual studio 2008\projects\page358number8\page358number8\page358number8.cpp(38) : error C2664: 'circumference' : cannot convert parameter 1 from 'double (__cdecl *)(int,int,int,int)' to 'double'
1>        Context does not allow for disambiguation of overloaded function
1>Build log was saved at "file://c:\Users\Willy\Documents\Visual Studio 2008\Projects\Page358Number8\Page358Number8\Debug\BuildLog.htm"
1>Page358Number8 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I've tried making all of the variables and functions double and it outputs the same error.
cout<< area(radius);

radius is a function, not a variable. Either store the result of radius into another variable and pass it in or supply arguments to the function so that you get the radius out of it.
In:
1
2
3
4
double radius(int x1, int y1, int x2, int y2);
double area(double radius);
//...
cout << area(radius);
You should be able to see that you're passing in the wrong type. area takes a value, but your passing in a function. You need to pass in the value from that function as in.
1
2
double r = radius(x1, y1, x2, y2);
cout << area(r);
or
 
cout << area(radius(x1, y1, x2, y2));
Topic archived. No new replies allowed.