Getting Started in Microsoft Visual Studio 2008 Console Application Tutorial
----------By Polymath
Table of Contents:
----------Part 1: Introduction
----------Part 2: Opening, Coding, Testing, and Final Work
----------Part 3: Line-By-Line Breakdown of the C++ Code Supplied
IntroductionThis Tutorial assumes that you have little-to-no knowledge of the C++ Programming Language and are using Microsoft Visual Studio as you first compiler to create a CONSOLE application. The "Help" documentation provided with the piece of software was not helpful to a non-C++ savvy programmer (me at the time), so I had to start from scratch. I couldn't find a sufficiently easy step by step tutorial for creating basic first-time applications, so I wanted to help any similarly-situated people by writing a concise, easy-to-follow, step-by-step w/screenshots tutorial. Plain and Simple.
Due to the uselessness and waste of memory of such programs as "helloworld.exe", in this tutorial we are going to create an EXTREMELY SIMPLE calculator that can add two numbers together. An added advantage of using this program for the tutorial is that it allows me to demonstrate more aspects of C++. Since this tutorial does not cover object-oriented-programming or other C++ -only functions, this could technically be considered a C tutorial, but it works for C++.
All that aside, let's begin.
Opening, Coding, Testing, and Final WorkStep 1. First, if you haven't already, download Microsoft Visual C++ Studio 2008 Express Edition for free at
The Microsoft Visual Studio Downloads Page. This download may take a while to install.
Step 2. Register and Launch Microsoft Visual C++ Studio 2008 (from here-on-out I will refer to this as Visual C++). The registration process is quick and easy.
Step 3. In Visual C++, select "File Menu-->New-->Project" (as shown).
Step 4. In the dialog box that pops up, click on "Win32" in the side pane and select "Win32 Console Application." Make sure that the "Create Directory for Solution" box is NOT checked and leave the default path the same (as shown---You can leave the Create Directory for Solution box checked and change the default path, but for purposes of this tutorial, leave it at the settings shown)
Step 5. The Win32 Application Wizard will pop up (as shown). Click "Next."
Step 6. Make sure that the following are checked (as shown):
----------1. Under "Application type": Console Application
----------2. Under "Additional Options": Empty Project
----------Then: Press "OK"
Step 7. Go to the "Solution Explorer" on the left side and right-click on "AddCalc" but be sure not to right click on "Solution AddCalc (1 project)." Once you have right clicked on AddCalc select "Add-->New Item"
Step 8. In the Dialog Box that appears, on the left pane select "Visual C++" and on the top section choose "C++ file (.cpp)" and change the name to AddCalc (as shown). Press "OK".
Step 9. A blank screen will appear showing the contents of "AddCalc.cpp" (as shown in SS1). Copy and Paste the following code into this blank white area (for a line-by-line breakdown of the code, go to part 3):
CODE
// initializing C++
#include <iostream>
using namespace std;
// declaring function prototypes
float addition (float a, float b);
//main function
int main ()
{
float x; //
float y; //declares variables
float n; //
int b;
b = 1; //sets value of b to 1
cout << "Simple Addition Calc- First Program"; //displays info about program
while (b==1) //creates loop so the program runs as long as the person wants to add numbers
{
//following code prompts the user for 2 numbers to add and calls function addition to display results
cout << "\n" << "Type a number to add (can also use negetive, decimals, etc.): ";
cin >> x;
cout << " Second number: ";
cin >> y;
n = addition (x,y);
cout << "Ans: " << x << " + " << y << " = " << n << "\n";
//following code sets b to the value the user imputs to determine if the loop is broken to end the program
cout << "Solve another operation? (1=yes, 2=no): ";
cin >> b;
cout << "\n";
if (b==2)
cout << "Terminating application.";
}
//ends the main function of the code
return 0;
}
//following function adds the numbers
float addition (float a, float b)
{
float c;
c = a+b;
return (c);
}
//END C++ CODE
Step 9. (con.) The blank area with the code in it is shown in SS2 along with the SAVE ALL button highlighted (you may wish to save your work here).
SS1:

SS2:
Step 10. Go to the Build Menu and select "Build Solution" (as shown).
Step 11. Your Output Screen (near the bottom of the page) should show the following (the most important being: *Build: 1 succeeded, 0 failed, 0 skipped, 0 up-to-date*):
Step 12. PRESS F5 on you keyboard, and a small box should pop up that is running your program that will add 2 numbers together (as shown). This is command to debug your application, which for our purposes is synonymous to testing.
Step 13. The Debug window should work. Assuming it does, to save your program to AddCalc.exe, first go to the drop down menu near the top of the screen which says "Debug" and change it to "Release" (as shown).
Step 14. Go to the Build menu and select "Rebuild" (as shown). This should give output that is SIMILAR, not the SAME as the output from Step 11.
Step 15. Go to Windows Explorer and go to:
"C:\Documents and Settings\
your_username_here\My Documents\Visual Studio 2008\Projects\AddCalc\Release"
(as shown below) Double click on AddCalc.exe, and if it runs, you can delete the other files in this directory.
Line-by-Line breakdown of the AddCalc.exe codeSome notes: There are some basic things about C++ that you should know beforehand. First, in C++ all spacings are equivilant (space, tab, enter), and you can have any number of the spacings, so an enter and a space both together means the same thing as a single enter or a single space. Second, a line that has // in it has a comment in it. The comment is whatever is in that line of code after the // untill there is an enter character (this is the only case in which an enter character is not the same as a tab or a space). I will ignore all comments in this code. Finally, all lines of code should end with a semicolon.
And without further ado, let's begin. I ignored comments because the comment will be the explination aligned to the right of the line it is in.
LINE-BY-LINE#include <iostream> // this tells c++ that we want to use the normal imput and output library NO ; REQUIRED
using namespace std; // this tells c++ that we are using the standard section of this library and the C++ language
float addition (float a, float b); //this says that after the main function we will have a seperate function "addition"
int main () //says that the next block of code is the main code to be executed.
{ //the curly brace starts the main function's block of code
float x; //declares a variable that can use numbers with decimels and negetives
float y; //declares variables that is the same as above
float n; //declares a variable, same type as x
int b; //declares a variable that can only use whole numbers
b = 1; //sets value of b to 1
cout << "Simple Addition Calc- First Program"; //displays info about program
while (b==1)
//creates loop so the program runs as long as the person wants to add numbers (when b=1)
{ //curly brace starts the loop block of code
cout << "\n" << "Type a number to add (can also use negetive, decimals, etc.): ";
// prints a newline "/n" and outputs for the user to specify a number
cin >> x; // provides imput for x after the string in the previous line.
cout << " Second number: "; // outputs "Second number: "
cin >> y; // provides imput for y after previous string
n = addition (x,y); // sets n to the value returned by addition for x and y
cout << "Ans: " << x << " + " << y << " = " << n << "\n"; // Displays answer
//following code sets b to the value the user imputs, and b is the variable for the loop above
cout << "Solve another operation? (1=yes, 2=no): "; //output
cin >> b; //imput
cout << "\n"; //Outputs new line
if (b==2) //if the user imput is 2
cout << "Terminating application."; //output
} //curly brace sends ends the loop and then it is reassesed whether or not b fits the loop to go again.
return 0; //ends the main function of the code
} //curly brace ends main function
float addition (float a, float b) //creates a function returning a decimal value
//this function requires two variables in its call of type float.
{ //starts function
float c; //creates a variable called c
c = a+b; //stores the value a+b as c
return ( c ); //c is the value given to the function call for addition
} //ends function
And thats it! the basics of c++ are very simple. For those of you who prefer a list of commands and definitions:
#include <library> --------------- says you are using commands from a library of c++ commands
using namespace [namespace] ------------- says you are using a subset of commands called namespace
cin >> variable ----------- stores user imput to variable
cout << variable/"string" << variable/"string" << ... ---------------------- outputs
varType function ([paramaters]) -----------------defines a function later in the program, or with {} creates
function commands
varType = value --------------------defines variable
while (variable==value) {}-------creates a loop that repeats as long as the variable is the same as the value
if (variable==value) [if more than one command: {}] ----------------------- runs a conditional statement
functionName ([paramaters]) --------------"calls" a function, the value of the call= the "return" of the function
return (variable)/value ------------------says what value the function should send back to its "caller"
This is only the very basics, I would suggest you go to the
cplusplus.com C++ Language Tutorial for a more complete reference of the language that includes commands not used in the AddCalc.exe program and a better syntax reference. Otherwise, this should be simple egnough for learning how to use a new interface (the basis of this tutorial).