Why cpp isn't working for me ?

Hi,
I just joined Codechef.com and was trying the life, universe problem under the easy category.

I originally wrote the code using C++ on Code::Blocks IDE but codechef kept returning my answers as wrong, runtime error, etc. When I adapted the same code to C and submitted it, the answer was accepted without any errors.

Why is this so? Can’t I program in C++ in codechef. Or is there any steps to be followed to make the compiler accept my cpp code ?

The codes I submitted were :

C++ code :

#include <iostream>
using namespace std ;
int main ()
{
    int num ;
    num = 0 ;
    while ( ( cin >> num )!= 0 && num != 42 )
    {
        cout << num << endl ;
    }
    return 0 ;
}

C code :

#include <stdio.h>
int main ()
{
    int num ;
    num = 0 ;
    while ( ( scanf("%d",&num) )!= 0 && num != 42 )
    {
        printf("%d\n",num);
    }
    return 0 ;
} // end of c code.

Please help. Awaiting answers.

Thank you.

P.S.: You can also contact me through email [[email protected]].

you havent used - “using namespace std;”
check this link:
http://www.codechef.com/viewsolution/3946219

and here is link to your solution http://www.codechef.com/viewsolution/3946127 that you have submitted

In youe submitted code : " using namespace std " is missing .
Here is your corrected code .

#include <iostream>
using namespace std ;
int main ()
{
    int num ;
    num = 0 ;
    while ( ( cin >> num )!= 0 && num != 42 )
    {
        cout << num << endl ;
    }
    return 0 ;
}