Cube Root Calculator

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2005
Posts: 17
Reputation: mdbrock7 is an unknown quantity at this point 
Solved Threads: 0
mdbrock7 mdbrock7 is offline Offline
Newbie Poster

Cube Root Calculator

 
0
  #1
Apr 25th, 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. 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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Cube Root Calculator

 
0
  #2
Apr 25th, 2005
IIRC:
  1. pow ( abs ( val ), 1.0 / 3.0 )
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 17
Reputation: mdbrock7 is an unknown quantity at this point 
Solved Threads: 0
mdbrock7 mdbrock7 is offline Offline
Newbie Poster

Re: Cube Root Calculator

 
0
  #3
Apr 25th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,457
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 251
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Cube Root Calculator

 
0
  #4
Apr 25th, 2005
"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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Cube Root Calculator

 
0
  #5
Apr 25th, 2005
>it would greatly help me to see the entire program from start to finish
  1. #include <cstdlib>
  2. #include <cmath>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. int val;
  8.  
  9. std::cout<<"Enter a number: ";
  10.  
  11. if ( std::cin>> val ) {
  12. std::cout<<"Cube root of "<< val <<": "
  13. << std::pow ( std::abs ( val ), 1.0 / 3.0 ) <<std::endl;
  14. }
  15. }
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 17
Reputation: mdbrock7 is an unknown quantity at this point 
Solved Threads: 0
mdbrock7 mdbrock7 is offline Offline
Newbie Poster

Re: Cube Root Calculator

 
0
  #6
Apr 25th, 2005
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?
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. double x;
  10. double a = 1;
  11. double b;
  12. char c;
  13.  
  14. c = ' ';
  15.  
  16. while (c != 'q')
  17. {
  18. cout << "Cube Root Calculator" << endl;
  19. cout << endl;
  20. cout << "Enter a number: ";
  21. cin >> x;
  22.  
  23. while (x - (a)(a)(a)) < 0.001)
  24. {
  25. a = b;
  26. }
  27.  
  28. cout << "Answer is: " << fixed << showpoint << setprecision(5) << a << endl;
  29. cout << endl;
  30. cout << "Press c to continue, q to quit" << endl;
  31. cin >> c;
  32. }
  33.  
  34. cout << "Exiting Cube Root Calculator" << endl;
  35. cout << endl;
  36.  
  37. return 0;
  38. }
Code reformatted and tags added. -Narue
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Cube Root Calculator

 
0
  #7
Apr 25th, 2005
>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:
  1. while (x - (a * a * a)) < 0.001)
>a = b;
b doesn't have a value yet. You'll probbly get strange results.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 17
Reputation: mdbrock7 is an unknown quantity at this point 
Solved Threads: 0
mdbrock7 mdbrock7 is offline Offline
Newbie Poster

Re: Cube Root Calculator

 
0
  #8
Apr 25th, 2005
Originally Posted by Narue
b doesn't have a value yet. You'll probbly get strange results.
What should i do with b?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Cube Root Calculator

 
0
  #9
Apr 25th, 2005
>What should i do with b?
How should I know, it's your program. You put b there for a reason, right?
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 17
Reputation: mdbrock7 is an unknown quantity at this point 
Solved Threads: 0
mdbrock7 mdbrock7 is offline Offline
Newbie Poster

Re: Cube Root Calculator

 
0
  #10
Apr 25th, 2005
I guess I need to come up with a formula for computing b.
This could take a while :-|
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC