Author Topic: Performing square root calculations in c++?  (Read 6363 times)

Ant

  • *
  • Posts: 402
    • View Profile
Performing square root calculations in c++?
« on: 2001-11-20 13:09:00 »
How do you perform square root calculations in c++ ?

Thanks

The SaiNt

  • *
  • Posts: 1300
    • View Profile
Performing square root calculations in c++?
« Reply #1 on: 2001-11-20 13:55:00 »
There is a header file you can include called math.h
Then you can use the function

sqrt(the number you want to squareroot);

Ant

  • *
  • Posts: 402
    • View Profile
Performing square root calculations in c++?
« Reply #2 on: 2001-11-20 15:11:00 »
Thanks SaiNT

Aaron

  • *
  • Posts: 2818
    • View Profile
    • http://aaron-kelley.net/
Performing square root calculations in c++?
« Reply #3 on: 2001-11-27 12:31:00 »
Can't you also do like

x^0.5

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Performing square root calculations in c++?
« Reply #4 on: 2001-11-27 14:24:00 »
Don't think so; C++ has this fixation with using symbols for as many things as possible ... I believe ^ is used to do binary XOR.

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Performing square root calculations in c++?
« Reply #5 on: 2001-11-27 17:56:00 »
C++ has the pow(number, tothepowerof) function, I think. It's in the math.h library.

Ant

  • *
  • Posts: 402
    • View Profile
Performing square root calculations in c++?
« Reply #6 on: 2001-11-27 19:58:00 »
Aaron : I was doing that for a while wondering why it was spewing out some hideous result.(Too much VB on the brain - not a good thing :smile: )

Darkness

  • *
  • Posts: 2181
    • View Profile
    • http://www.x0r.net
Performing square root calculations in c++?
« Reply #7 on: 2001-11-27 23:48:00 »
i dont completely understand the isdigit command of ctype.h..... I input 5 and get 4..... why? shouldn't i get 1?

The SaiNt

  • *
  • Posts: 1300
    • View Profile
Performing square root calculations in c++?
« Reply #8 on: 2001-11-28 00:39:00 »
Quote

On 2001-11-27 19:48, Darkness wrote:
i dont completely understand the isdigit command of ctype.h..... I input 5 and get 4..... why? shouldn't i get 1?

How exactly did you use it?

Darkness

  • *
  • Posts: 2181
    • View Profile
    • http://www.x0r.net
Performing square root calculations in c++?
« Reply #9 on: 2001-11-28 00:42:00 »
i was messing with it in my c++ class today......

something like this:

cin >> i;
x = isdigit(i);
if (x == 1)
{
       cout << "Character is a Digit";
}
else
{
       cout << "Character is not a Digit";
}

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
Performing square root calculations in c++?
« Reply #10 on: 2001-11-28 12:58:00 »
As the help says, isdigit returns nonzero if it is a number, else returns 0.

In c++ false = 0. true = anthing else.

fix that line to: if ( x )
or make it:
if (x == 0)
   cout << "Character is not a Digit";
else
   cout << "Character is a Digit";

Darkness

  • *
  • Posts: 2181
    • View Profile
    • http://www.x0r.net
Performing square root calculations in c++?
« Reply #11 on: 2001-11-28 21:32:00 »
yup. i fixed it earlier today. thats the EXACT words of my textbook.