![]() |
|
#1
|
|||
|
|||
C++ math problemhello all,
im trying to code what should be a pretty simple math problem as an asignment for my c++ class but it isnt working out so well. so here is the code i have now .. as you can see its to compute area and circumference of and ellipse. CPP / C++ / C Code:
when i try to compile this i get "too few arguments to function 'double pow(double, double)" on the circumference line. im guessing that means the () are wrong somewhere but i cant seem to find where. i dont really need a coded response or anything, im just trying to figure out what that error as i have gotten the same thing on another similar program im working on. any help would be appreciated ... and its my first post so be gentle if i made a stupid mistake |
|
#2
|
||||
|
||||
Re: c++ math problemBreak this statement
CPP / C++ / C Code:
__________________
Age is unimportant -- except in cheese |
|
#3
|
|||
|
|||
Re: C++ math problemah ok ill give that a try to see how it works out. it also works when its entered like this,
CPP / C++ / C Code:
is that the compiler just getting confused? or is it just a better programming practice to split things like that. |
|
#4
|
|||
|
|||
Re: C++ math problemQuote:
CPP / C++ / C Code:
CPP / C++ / C Code:
__________________
Music, programming, endless learning.. |
|
#5
|
|||
|
|||
Re: C++ math problemQuote:
CPP / C++ / C Code:
For purposes of human clarification, I will replace pow(a,2.0) by powa, and I will replace pow(b,2.0) by powb CPP / C++ / C Code:
If you still don't see the problem, then substitute powab in place of powa + powb CPP / C++ / C Code:
If you still don't see it, substitute powabover2 for (powab)/2.0 CPP / C++ / C Code:
Quote:
That's a value judgment that I will leave to you. Some people can spot errors and write correct code for very complicated expressions. I promise you, the compiler doesn't "get confused," (If it does, then demand your money back!) but people who have to maintain the code may not be as sophisticated as the people who write the code. If I have to spend more than three seconds debugging an incorrect expression, then simplify it; that's my rule of thumb. As far as better programming practice: I rarely call pow(x, 2.0) for simple variables. I just use x*x. Some would call that better (since multiplication is likely to be "more efficient" than calling a mathematical function). Some would call it worse (for a number of reasons). I can't see me ever calling pow(x, 0.5); I would (probably) use sqrt(x) with the reasoning that the library function sqrt is specifically optimized for square roots, whereas the library function pow works as a square root when its second argument is 0.5, but may not be as "efficient". Note that optimizing compilers and optimized library functions may very well take care of special cases and create code more "efficient" that you could dream of. Bottom line: if it makes sense to you (and if it works), then that's OK. If you, the person writing the code, have problem parsing a complicated expression, consider the difficulty of maintaining the code, and take whatever steps you deem appropriate. On the other hand, I do have some other suggestions that I consider "good programming practice" 1. Use standard C++ headers. The deprecated headers that you use may not be supported in future revisions of C++ compilers. 2. Always test state of streams that your program attempts to open. 3. (More a matter of personal taste.) Use constants instead of calling library functions to calculate constants at run time. The value of pi is #defined as M_PI in some <math.h> headers, but not all of them have it. I think that best programming practice is probably to use the value in the program. (I usually just use M_PI, for my own code, since I know that my <math.h> has it #defined to be the value of pi to a precision that is at least as good as the double variables, but if I am going to ship the code to someone else, I just paste the value into the program.) Note that, traditionally, programmers typically use all caps for manifest constants. So, the first part of my program might look like CPP / C++ / C Code:
There are other possible styles that might considered to be "good programming practice". I invite comments. Regards, Dave Footnote: Some people always print error messages to cerr rather than cout to take into consideration the possibility that standard output may be redirected to a file or piped to another program. |
|
#6
|
|||
|
|||
Re: C++ math problemGreat responses, thx for the help folks
- ill keep all those suggestions in mind for sure.... as for now im still at the stage where its the professor saying do it this way... which accounts for the pi=acos-1 and some of the other stuff... but again, thx for the help |
Recent GIDBlog
Developing GUIs with wxPython (Part 2) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Math problem: Total Noob | Targsmom | C Programming Language | 3 | 20-Oct-2006 05:05 |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 12:31 |
| Runtime Problem involving "printf" in C Program | supamakia | C Programming Language | 2 | 09-Oct-2005 10:09 |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 07:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The