Compile Error

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
kmd
New poster
Posts: 2
Joined: Fri Apr 11, 2003 7:13 pm
Location: Taiwan, an independent country

Compile Error

Post by kmd »

I got "compile error" in the online judge.

But I've tried to compile my source code with g++ on my FreeBSD, Dev-C++ & VC++ on my Windows, without getting any errors.

Does anyone have a hint?
Your opinion will be appreciated. :-)

[cpp]#include<iostream>
#include<iomanip>
#include<cmath>
#define PI 3.1415926535
using namespace std;

int main(){
double D, V;
long double d;
while(cin >> D >> V){
if(D==0 && V==0) return 0;

d = cbrt( pow(D,3)-6*V/PI );
cout.setf(ios::fixed);
cout << setprecision(3) << d << endl;
}
}[/cpp]
kmd
New poster
Posts: 2
Joined: Fri Apr 11, 2003 7:13 pm
Location: Taiwan, an independent country

Post by kmd »

Now I see what's the problem in my code :-)
The online judge environment isn't compatible with the "cbrt()" function in cmath header file :o
Juergen Werner
New poster
Posts: 27
Joined: Wed Apr 17, 2002 7:54 pm

Post by Juergen Werner »

Since the judge uses GCC, it could compile it since GCC supports cbrt(), but as far as I know they compile with the '-ansi' option, and cbrt() does not conform to ANSI.

Code: Select all

CBRT(3)             Linux Programmer's Manual             CBRT(3)
...
CONFORMING TO
       cbrt is a GNU extension.
cbrt() can be substituted using pow which is also contained in 'math.h':

Code: Select all

cbrt(a)
pow(a, 1.0/3.0)
Btw, you can also get PI by

Code: Select all

const double PI = 2 * acos(0);
Maxim
New poster
Posts: 38
Joined: Tue Aug 27, 2002 12:36 am
Location: Croatia
Contact:

Post by Maxim »

Juergen Werner wrote:Btw, you can also get PI by

Code: Select all

const double PI = 2 * acos(0);
For simplicity,

Code: Select all

const double PI = acos(-1.0);
:P

Maxim
Post Reply

Return to “C++”