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

×

Compilation Error

My program runs perfectly fine on my pc. But while submitting it on code chef, it shows a long list of compilation errors.
I am a first time submitter... please review my code and help! :)
By the way, I use Turbo C++.

#include <iostream>
using namespace std;

int main()
{
  int t,x,n;
  std::cin>>t;

  while(t--)
  {
    std::cin >> n;
    x=(n/2) + (n/3) + (n/4);
    if (x>n)
      std::cout <<x<<;  // The error is here. Use std::cout <<x<< endl;
    else
      std::cout <<n<<;  // And here as well.
   }
   return 0;
 }

Edited by @anton_lunyov to fix the code display issue and also to indicate errors directly in code.

asked 21 Apr '13, 16:27

sanjam_kumar's gravatar image

2★sanjam_kumar
1113
accept rate: 0%

edited 21 Apr '13, 18:40

anton_lunyov's gravatar image

6★anton_lunyov ♦
6.7k62119138


you have some error syntax. 1)include iostream wrong -correct version #include <iostream> 2) you use namespace std so you don't need std:: delete all 3) after cout<<x<<; is wrong you must write something after <<, like this cout<<x<<'n';

link

answered 21 Apr '13, 17:58

shikimaru's gravatar image

3★shikimaru
4361014
accept rate: 0%

Hello,

You can also use cout << n << endl; to fix the cout formatting error...

Using std::cout after using namespace std, is not an error, just unnecessary code :)

Best regards,

Bruno

link

answered 21 Apr '13, 18:04

kuruma's gravatar image

3★kuruma
17.7k72143209
accept rate: 8%

include <iostream>

include <string>

using namespace std;

int main( ) { cout << "Bob is my buddy; cout << " and so is Mary" << endl; }

causes these compiler errors

string.cpp:7:12: warning: multi-line string literals are deprecated string.cpp: In function int main()': string.cpp:7:so' undeclared (first use this function) string.cpp:7: (Each undeclared identifier is reported only once for each function it appears in.) string.cpp:7: parse error before `Mary' string.cpp:8:28: warning: multi-line string literals are deprecated string.cpp:8:28: missing terminating " character string.cpp:7:12: possible start of unterminated string literal

Meaning

The compiler thinks that you are trying to create a multi-line string which is no longer a supported feature of the language

Usual Causes You're missing a quote mark at the end of one of your strings

link

answered 28 Apr '13, 11:25

sowji's gravatar image

0★sowji
1
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:

×2,718
×2,345
×19

question asked: 21 Apr '13, 16:27

question was seen: 1,568 times

last updated: 28 Apr '13, 11:25