# C++ cube root calculator



## mdbrock7 (Apr 29, 2005)

I am a complete newbie in C++ programming. After a very basic introductory class I am now reading a little more advanced book and trying to teach myself and I am slowly learning. Anyway, the book mentions a method for calculating the cube root of a number but it doesn't give any actual examples. It left me a little confused. I was trying to follow the book and my code looks like this. It doesn't work yet but I'm still working on it.
Does my code make sense to you at all?
I know I need to somehow calculate "b" but I have no clue. Can you make any suggestions on how to finish it or tell me if I'm even close?

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
double x;
double a = 1;
double b;
char c;

c = ' ';

while (c != 'q')
{
cout << "Cube Root Calculator" << endl;
cout << endl;
cout << "Enter a number: ";
cin >> x;

while (x - (a*a*a)) < 0.001)
{
a = b;
}

cout << "Answer is: " << fixed << showpoint << setprecision(5) << a << endl;
cout << endl;
cout << "Press c to continue, q to quit" << endl;
cin >> c;
}

cout << "Exiting Cube Root Calculator" << endl;
cout << endl;

return 0;
}


----------



## Shadow2531 (Apr 30, 2001)

Don't really have time to directly help you, but this thread shows how to get the square root, so it may help you in getting the cubed root. (There's c++ in that thread)


----------



## IMM (Feb 1, 2002)

I find it hard to tell what method you are trying to use
Does the source which you are reading mention Newton ?

BTW - if you just want the cube root using C++, then a calculation like
z = pow(input, 1.0/3.0)
(where input and z are doubles) will work fine


----------

