Missouri 4-H Robotics
Would you like to react to this message? Create an account in a few clicks or log in to continue.

The first program

Go down

The first program Empty The first program

Post  Admin Mon Mar 25, 2013 11:56 am

Running the first example exercise.

to create a new program in Visual C++, you
open Visual C++
click on New Project
select Win32 Console Application
Enter a file name and click OK
Click Finish to accept the current settings

You will see your program in the large window in the middle of the screen, another window on the left that shows the directory structure of files included in your program, including all the other files that get created when you first create a new program, and a third window at the bottom of the screen that shows 'output' or 'command window' or 'find results' depending on which tab you have selected.

The default code that was automatically placed in the program looks like:

// first2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}



This is similar to the program shown in Thinking about C , but the format for the main function is a bit different, and the name of the header file that is included is different. We'll leave those as is, as that's what the compiler is expecting and just change the block of commands to include the puts commands. The new program should look like this:

// first.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
puts("** Welcome to Thinking in C **");
puts("(You'll be glad you came! )");
return 0;
}


Before running the program, you need to Build it.
Click on Debug - Build Solution (or just click on F7)
In the output window you should see Build: 1 succeeded, 0 failed

If it failed, you may have missed typing in a quotation mark, or a parentheses. It should give you an error statement that will help you figure out what went wrong. Make the correction, and rebuild (F7).

Once you see that the build has succeeded, click on Ctrl-F5. That will run the program and show the console window. You should see your output in the window.

** Welcome to Thinking in C **
(You'll be glad you came!)
Press any key to continue . . .


If you have any problems with this, reply to this thread and we'll get you on track.


Admin
Admin

Posts : 9
Join date : 2012-04-02

https://parklandscience.board-directory.net

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum