Hello I am new to C++ and coding. A few years ago I decided to learn C++ and wanted to start off by making a text based game to start off. So I brought a few books and began reading and doing the tutorials for things like 'Hello World', 'Calculator', 'Rolling Dice'. I did a lot of experimenting with input but became distracted with trying to get through High School that the work I was learning sort of sat there.

Only a few years later I have decided that I want to have an understanding of C++ but that the programming is not for me. A friend of mine recently compiled a simple program to roll dice. He explained he can successfully compile it and even make it run in the compiler, but he does not know how to get the game to play as an executable file/or doesn't know how to export it into whatever format needed to play it as a regular game.

I apologize if my terminology is all wrong but it is the only way I know how to describe the barrier hit.

A friend of mine recently compiled a simple program to roll dice. He explained he can successfully compile it and even make it run in the compiler, but he does not know how to get the game to play as an executable file/or doesn't know how to export it into whatever format needed to play it as a regular game.

I apologize if my terminology is all wrong but it is the only way I know how to describe the barrier hit.

Yes, I think the terminology may be a bit inexact. I'm guessing you are using "compiler" when you mean "IDE". Just a guess though. Here are a few (rough) terms:

compiler = something that turns C++ code into an executable program.

Integegrated Development Environment(IDE) = Tools like Visual Studio, Net Beans, Code Blocks, and Eclipse that combine a compiler, editor, debugger, and other tools.

executable program = A compiled program that can be run on the computer with or without an IDE.


My guess is that your friend used an IDE like Visual Studio, typed in the source code, clicked "Build", which compiled the program, then "Run" which ran it inside the IDE.

If I am right, the program already is compiled and runnable. Your friend just does not know where the program is located and how to run it outside of the IDE. This will depend on the operating system and the IDE. It will also depend on the type of program (i.e. a console program or a graphical user interface).

First, find the program. Generally there are settings. You can have the IDE place the program wherever you want it to you. If it's Windows and Visual Studio and the name of the project was DiceRolling, there would probably be a folder like this:

C:\Documents and Settings\Vernon\My Documents\Visual Studio 2010\Projects\DiceRoling

and inside that somewhere would be a program called DiceRolling.exe that you can run. Go to that folder.

Simply double-click it to run it. If it is a CONSOLE program as opposed to a graphical program, it may run, then disappear really quickly. if that's the case, you want to get a command window open:

Start -> All Programs -> Accessories -> Command Prompt

then maneuver to the folder and run it from there.

As a side note, if that's the case, then this thread may be of interest.
http://www.dreamincode.net/forums/topic/30581-holding-the-execution-window-open/


Hope this helps. It could be a complete misreading of your situation.

Thank you, I was not sure what IDE was but kept seeing in different threads here but I wasn't sure what it all meant until now. (Thank you again for clarifying that for me)

He uses a Linux but I use a Windows, is it different for a Linux? I am going to try the suggestion out with him tonight thank you again!

My friend said that he finished and compiled it and when that didn't work he copied it into a different folder. He says it won't start or doesn't try to start.

His computer is: Ubuntu Linux

IDE: code::blocks

Here is a snapshot of his computer screen: http://img64.imageshack.us/img64/2667/screenshot67i.png

Main.c is the code and the one that says Main is the one he is clicking, and when he clicks it nothing at all comes up.

Thank you, I was not sure what IDE was but kept seeing in different threads here but I wasn't sure what it all meant until now. (Thank you again for clarifying that for me)

He uses a Linux but I use a Windows, is it different for a Linux? I am going to try the suggestion out with him tonight thank you again!

You're welcome. Linux is different in many ways, but the same in many ways. You may or may not be able to compile his program on Windows. That will depend entirely on whether he used any Linux-specific libraries when he wrote his code. If he used only the libraries here:

http://www.cplusplus.com/

you should be able to compile and run his code on Windows.

If he's using Linux, he won't have written the program using Visual Studio. He may, however, have used Code Blocks, Eclipse, or Net Beans as his IDE. Regardless, all IDEs work basically the same. There is a generic template for creating projects and there are default settings about where things are saved. You can override them if you like. They all compile a program, then you save that compiled program, then you can run the program without the IDE. You won't be able to take his compiled program and run it on Windows. You'll need to compile his source code on Windows(i.e. the actual C++ files that he wrote), then run it.

If you are on a different platform than he is (Linux vs. Windows) you're going to have to compile his code on a Windows machine. He could conceivably generate a Windows binary, but it's not the default and it's probably too much trouble at this point. have him send you the .c file. As long as there's all standard functions it should compile on both platforms.

EDIT: Vernon beat me to it. :)

Main.c is the code and the one that says Main is the one he is clicking, and when he clicks it nothing at all comes up.

He should go into a command line prompt (as opposed to the GUI Explorer) and change directories and try to run it from there. He needs to:

  1. Make sure it's the actual program. It may be in the "bin" directory too.
  2. When he finds the program, do this(assuming the program is called "main".
  3. ./main

./ means "run this program" in Linux.

He can also, at the command line, do the following:

gcc main.c -o myprogram
./myprogram

This will run it. No IDE needsed. It's all at the command line. As the link I posted before explains, often the program, when double clicked, will run, complete, then go away, all too fast for you to see anything.

When I ran the files on my computer it flashed open and shut really quick and so we realized that it was working and probably doing that on Linux but maybe was appearing too fast for him to see it.

Then we both did it in our command prompts. And it worked for both of us. Thank you both for your help.

A while back I remember there was a code I was told to put in which would make it not do that anymore. When I put it in the file would stay open. Does anyone know what that code is to keep it from closing really quick?

When I ran the files on my computer it flashed open and shut really quick and so we realized that it was working and probably doing that on Linux but maybe was appearing too fast for him to see it.

Then we both did it in our command prompts. And it worked for both of us. Thank you both for your help.

A while back I remember there was a code I was told to put in which would make it not do that anymore. When I put it in the file would stay open. Does anyone know what that code is to keep it from closing really quick?

See the first link in this thread that I posted. Also see these two:

http://www.gidnetwork.com/b-61.html
http://www.cplusplus.com/reference/clibrary/cstdio/getchar/

You use getchar() for C and cin.get() for C++. Sometimes you need to do it more than once. You were probably told to avoid using this command:

system("pause");

See the link I just linked for why as well as the first link in the thread.

system("pause");

is the quickest way to do it, but as WaltP mentions in the linked thread, it has drawbacks and is frowned upon and there are alternatives. But it DOES work if you want to use it.

Thank you so much, I have learned a lot today and appreciate the time you took to help me! I definitely don't want to start any bad habits, thank you again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.