Codes between Compilers

Pages: 12
closed account (1wvX92yv)
HI.
I use Turbo c++ with dosbox at home, and i wanted to enter an online competition for writing codes.
After i wrote the code, it worked perfectly.
But when i submit it, it says wrong output......but it works fine on my turbo c++.
On checking the help section, it say the judge environment is


C++ g++ 4.6.3 -std=c++0x -w -O2 -fomit-frame-pointer -lm

I dont know what that means........how do i get my code to work for them?

Any help regarding this problem will be highly appreciated
Can you download the gcc compiler or even an IDE with the gcc compiler in it?

Turbo C++ is seriously old (20+ years) anyway, so you might as well update.
closed account (1wvX92yv)
Dear theldeasman,
I am a student and I am just learning c++.
They teach me in turbo c++ and I am expected to use it in board examinations as well. Thus I am comfertable with it.......

I have tried visual c++ but couldn't work out how to make the program run......

if u could please help me regarding how to go about downloading the gcc ide, I would be highlygrateful

Thanks for ur help..........
closed account (1wvX92yv)
Also, is there a way to convert codes in turbo c++ into something that is compatible with gcc?
Often you get different compiler behavior with code which isnt conform to the standard. Fit your code in the concerned lines.
closed account (1wvX92yv)
But how do I know what the conform lines are?
how do i get my code to work for them?

Rewrite it in C++. "Turbo C++", despite the name, doesn't support C++, the language, as defined since 1998. (Before 1998, C++ was in active development and existed as a many constantly changing dialects and implementations, Turbo was one of them)
Last edited on
closed account (1wvX92yv)
So which compiler should I use to get the required result?
gcc?

The Errors you get show you the concerned code lines.
closed account (1wvX92yv)
It doesn't show me any lines.......just says the output is wrong.

But it works perfectly on my comp
..
if u could please help me regarding how to go about downloading the gcc ide, I would be highlygrateful


I use KDevelop on the Fedora Linux OS, but for you to do that, you will need a spare partition on your hard disk, or better a spare hard drive. The big thing is it is entirely free, and Linux has 20,000 free apps as well. It is great for IT, because you have free access to all kinds of programming languages, scripting and environments. Popular Linux distributions include Fedora, Ubuntu, Suse plus lots of others.

If using windows, I have heard that codeblocks is good, and is free. I haven't used it though, but lots of people on this forum have. There is also MINGW and the clang compiler is good (it has easy to read compiler messages).

IDE stands for Integrated Development Environment, and is a program that has an editor, compiler, linker, debugger plus all kinds of other handy tools to make writing applications easier. A compiler is only part of that - it turns your C++ code into an executable program. IDE's usually come with compiler as well (they are useless without one), some of them you can change which compiler it uses.

If you have trouble using an IDE - just ask, there are lots of people who can help.
There are 3 possible problems:
Compiler Error: Outputs in which line the error is and a errormessage
Linker Error: Outputs an errormessage and the File/Symbol which causes the error
Program Error: The programm doesnt make what it should

Which is it?
closed account (1wvX92yv)
I have got no clue........but I'm pretty sure its not compiler error as it shows nothing in compile log.

As I said, I submitted a program to an online competition, it is not accepting it.
closed account (1wvX92yv)
Ok.........I wanna get codeblock.........now how do I go about it?

And is codeblock an ide?
Online compilers, such as http://ideone.com and http://liveworkspace.org can help show the compilation errors. You could also post a link to the pasted code here (after running it online)
Post the Code
Sometimes it can be small things. Users of TC++ often have this:

1
2
3
4
5
void main() //error must return an int
{
//code

}


Which is an error on a modern compiler. main must return an int.

This is one of many reasons why TC++ (version 3.0 anyway - not sure about v4.5) is not good. A massive galaxy sized in-your-face glaring thing is that there is no STL. C++ has moved on even further - now we have the C++ 2011 standard, which has about as much additional stuff as what is in the STL.

So all this means that whatever code you write in TC++ will be non-standard & non portable.

I am not sure why Indian schools still use TC++ when they could have a brand new Linux based one for free.
closed account (1wvX92yv)
this was the question................

You are asked to calculate factorials of some small positive integers.

Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output
For each integer n given at input, display a line with the value of n!
closed account (1wvX92yv)
and this is what i did...............

http://liveworkspace.org/code/3mQTbm$1
The message is clear - conio.h is not standard. You have it because of the clrscr function? There is an artilce on this site about that. Have a look - you should find it easily.

The compiler is stopping after 1 error. The others I can see:

> void main() I already mentioned.
> What is to be achieved by using long double? it only gives 2 extra digits of precision (18), which won't make any difference for larger factorial numbers.
> put std:: before cin, cout endl and any other std namespace thing.
> Do not use the double type in a for loop. Floating Point (FP include floats & doubles) are stored as binary fractions & cannot represent every number, they cause for loops to fail. Use integer types, then convert them to double inside the loop.
Pages: 12