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

×

c++ code not working

i tried submitting a code for a program which is running perfectly fine on turbo c++ but doesent seems to work here this is the code

include<iostream.h>

include<conio.h>

void main() { int n; for( ; ; ) { cin>>n; if(n==42) break; cout<<n; } getch(); }

pls suugest a solution :)

asked 31 Jul '14, 21:23

mongasarthak's gravatar image

0★mongasarthak
4612
accept rate: 0%

use iostream instead of iostream.h and include using namespace std; as the compiler may not be able to compile the old version and also remove conio.h and hence the getch().

(31 Jul '14, 22:02) moulesh1230★

@mongasarthak , the above mentioned would definitely help you , but to avoid such header files related queries you can compile your code on online compliers , for example if you submit this code on ideone clearly it gives an error ,and thus you would know from it , that this header file which you added wouldn't work on code chef too , so you can thus modify your code accordingly .

These error's are very common initially so don't worry much about it .

All the Best and happy coding :) .

link

answered 01 Aug '14, 05:04

its_pheonix's gravatar image

4★its_pheonix
2.3k62021
accept rate: 11%

edited 01 Aug '14, 05:08

  1. Use iostream instead of iostream.h and place a line using namespace std; after the header file declaration.
  2. Do not use conio.h as it is not a standard header file.
  3. Besides, getch() is not needed as its function is to see output on the screen, which is not needed here.
  4. The main function return type should be int instead of void
  5. You also need to use endl for newline cout<<n<<endl as the numbers are printed on newlines. Here is the corrected solution link: http://www.codechef.com/viewsolution/4410280
link

answered 31 Jul '14, 21:58

pratku123's gravatar image

4★pratku123
1.8k4932
accept rate: 14%

edited 31 Jul '14, 22:08

I too faced the same problem initially . :)

link

answered 02 Aug '14, 11:50

proxy_s's gravatar image

3★proxy_s
3113
accept rate: 0%

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:

×1,770
×228

question asked: 31 Jul '14, 21:23

question was seen: 2,200 times

last updated: 02 Aug '14, 11:50