You are not logged in. Please login at www.codechef.com to post your questions!

×

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 [bharathsoftdev@gmail.com].

asked 26 May '14, 15:45

bharathyes's gravatar image

2★bharathyes
11
accept rate: 0%

edited 26 May '14, 15:51


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

link

answered 26 May '14, 15:57

sanzzzay's gravatar image

2★sanzzzay
7223820
accept rate: 12%

edited 26 May '14, 15:59

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 ;
}
link

answered 26 May '14, 16:25

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,284
×180
×89
×50

question asked: 26 May '14, 15:45

question was seen: 810 times

last updated: 26 May '14, 16:25