function square

P

Player

Hi,
I'm beginner and have problems by using function square from math.h

Compajler:
Borland C++ 5.5.1 for Win32

Code:

#include <iostream.h>
#include <math.h>
int main() {
float r,k,x,y,z;
//long z;
cout <<"Enter x:";
cin >> x;
cout << "Enter y:";
cin >> y;
if (abs(x) != abs(y)) {
cout << "Enter r:";
cin >> r;
cout << "Enter k:";
cin >> k;
z = (square(r) * k) / (square(x) - square(y));
cout << "Rezults: " << z << endl;
}
else {
cout << "Funkcija nije definisana za date vrijednosti x i y \n";
return 0;
}
}

Compile Error:
Error E2268 Call to undefined function 'square'in function main()


Where I'm wrong?
 
J

John Harrison

Player said:
Hi,
I'm beginner and have problems by using function square from math.h

Compajler:
Borland C++ 5.5.1 for Win32

Code:

#include <iostream.h>
#include <math.h>
int main() {
float r,k,x,y,z;
//long z;
cout <<"Enter x:";
cin >> x;
cout << "Enter y:";
cin >> y;
if (abs(x) != abs(y)) {
cout << "Enter r:";
cin >> r;
cout << "Enter k:";
cin >> k;
z = (square(r) * k) / (square(x) - square(y));
cout << "Rezults: " << z << endl;
}
else {
cout << "Funkcija nije definisana za date vrijednosti x i y \n";
return 0;
}
}

Compile Error:
Error E2268 Call to undefined function 'square'in function main()


Where I'm wrong?

There is no function square in math.h. Who told you that there was?

It's not hard to write you own of course.

john
 
O

osmium

Player said:
I'm beginner and have problems by using function square from math.h

Compajler:
Borland C++ 5.5.1 for Win32

Code:

#include <iostream.h>
#include <math.h>
int main() {
float r,k,x,y,z;
file://long z;
cout <<"Enter x:";
cin >> x;
cout << "Enter y:";
cin >> y;
if (abs(x) != abs(y)) {
cout << "Enter r:";
cin >> r;
cout << "Enter k:";
cin >> k;
z = (square(r) * k) / (square(x) - square(y));
cout << "Rezults: " << z << endl;
}
else {
cout << "Funkcija nije definisana za date vrijednosti x i y \n";
return 0;
}
}

Compile Error:
Error E2268 Call to undefined function 'square'in function main()


Where I'm wrong?

There is no function square in <math.h> and you didn't provide a prototype
for one, either. The compiler correctly concluded that it had no such
function. Use your editor and examine math.h. The usual way to get a
square is x*x.
 
T

Tuyen Do

You may need the function "pow" in "math.h".

[
double pow(double x, double y);
]
Calculates x to the power of y.






T. Do
 
M

Mike Wahler

Player said:
Hi,
I'm beginner and have problems by using function square from math.h

There is no function called 'square' in the
C standard library. But of course it's simple
to write one.
Compajler:
Borland C++ 5.5.1 for Win32

Code:

#include <iostream.h>

#include <math.h>

template <typename T>
T square(const T& value)
{
return value * value;
}
int main() {
float r,k,x,y,z;
file://long z;
cout <<"Enter x:";
cin >> x;

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top