| | |
Cube Root Calculator
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 17
Reputation:
Solved Threads: 0
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. Is there a website that any of you are familiar with where it shows the code for this and other basic programs for me to quickly refer to when I get stuck on a particular problem? I googled "cube root calculator" but it didn't return much. I don't want to continue reading forward until I get the hang of this problem.
IIRC:
C++ Syntax (Toggle Plain Text)
pow ( abs ( val ), 1.0 / 3.0 )
New members chased away this month: 4
•
•
Join Date: Apr 2005
Posts: 17
Reputation:
Solved Threads: 0
Thanks for your help but with me being such a C++ idiot it would greatly help me to see the entire program from start to finish. I'm still getting the hang of loops and it would be nice to see the while loops referred to in the book. I'm trying to write it out myself but I'm not having much luck. I'll keep searching. Thanks again
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
>it would greatly help me to see the entire program from start to finish
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <cmath> #include <iostream> int main() { int val; std::cout<<"Enter a number: "; if ( std::cin>> val ) { std::cout<<"Cube root of "<< val <<": " << std::pow ( std::abs ( val ), 1.0 / 3.0 ) <<std::endl; } }
New members chased away this month: 4
•
•
Join Date: Apr 2005
Posts: 17
Reputation:
Solved Threads: 0
Holy cow! That one is more advanced than I am. I was trying to follow the book and mine looks like this. It doesn't work yet but I'm still working on it. Can you tell me if I am even close?
Code reformatted and tags added. -Narue
C++ Syntax (Toggle Plain Text)
#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; }
>That one is more advanced than I am
Aroo? And then you post a manual attempt at it? :eek:
>while (x - (a)(a)(a)) < 0.001)
(a)(a)(a) likely doesn't do what you think it does.
Perhaps you were trying to do:
>a = b;
b doesn't have a value yet. You'll probbly get strange results.
Aroo? And then you post a manual attempt at it? :eek:
>while (x - (a)(a)(a)) < 0.001)
(a)(a)(a) likely doesn't do what you think it does.
Perhaps you were trying to do: C++ Syntax (Toggle Plain Text)
while (x - (a * a * a)) < 0.001)
b doesn't have a value yet. You'll probbly get strange results.
New members chased away this month: 4
![]() |
Similar Threads
- Cube Root Program [Homework Help] (C++)
- Cube Root (C++)
Other Threads in the C++ Forum
- Previous Thread: circular linked lists
- Next Thread: big numbers in C++ 5.4455e07
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






