function square

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Player

    function square

    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?
  • John Harrison

    #2
    Re: function square


    "Player" <alen@smartnet. ba> wrote in message
    news:f60ebd0d.0 307131141.5f419 6c5@posting.goo gle.com...[color=blue]
    > 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?[/color]

    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


    Comment

    • osmium

      #3
      Re: function square

      Player writes:
      [color=blue]
      > 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?[/color]

      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.


      Comment

      • Tuyen Do

        #4
        Re: function square

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

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






        T. Do


        Comment

        • Mike Wahler

          #5
          Re: function square


          Player <alen@smartnet. ba> wrote in message
          news:f60ebd0d.0 307131141.5f419 6c5@posting.goo gle.com...[color=blue]
          > Hi,
          > I'm beginner and have problems by using function square from math.h[/color]

          There is no function called 'square' in the
          C standard library. But of course it's simple
          to write one.
          [color=blue]
          >
          > Compajler:
          > Borland C++ 5.5.1 for Win32
          >
          > Code:
          >
          > #include <iostream.h>[/color]

          #include <iostream>
          using namespace std;
          [color=blue]
          > #include <math.h>[/color]

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

          -Mike



          Comment

          Working...