You are on page 1of 3

Displaying a Simple Message

Problem
A program that will display a simple welcome message.

Program
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello! We are Group 5!"<<endl;
return 0;
}
Output

Discussions

In creating a new program, you need to create a project and add a source file:
1. Create a project by pointing to New on the File menu, and then
clicking Project.
2. In the Visual C++ project types pane, click Win32, and then click Win32
Console Application.
3. Type a name for the project.
By default, the solution that contains the project has the same name as the project,
but you can type a different name. You can also type a different location for the
project.
Click OK to create the project.
4. In the Win32 Application Wizard, click Next, select Empty Project,and then
click Finish.
5. If Solution Explorer is not displayed, on the View menu, click Solution
Explorer.
6. Add a new source file to the project, as follows.
a. In Solution Explorer, right-click the Source Files folder, point to Add,
and then click New Item.
b. In the Code node, click C++ File (.cpp), type a name for the file, and
then click Add.
#include <iostream>
Means we include a certain library called iostream.
using namespace std;
Use as a support for the library and serves as a category or shelf.
The std means standard.
The semicolon (;) is used as a terminator.
int main ()
Means you are tagging main program.
The int means integer.
The main is a function coupled with the return 0 value at the end of the main
program.
What is inside in the { } it is called the main program.
The double quotation ( ) connotes the message that will be displayed.
Reserved words:
cout<<
used as an output or we are to display a message
cin>>
used as an input or you need to enter something
<<endl;
if there are two succeeding output to be programmed you need to put
(<<endl;) to separate first line and second line.
(cout<<endl;) means skipping the next line.
return 0;
means nothing is to be return
it is applicable only if you start with your body with int main()
Note:
The Visual Studio is case, symbol and space sensitive.
All lines in the main program has semicolon(;) as ending which serves as a terminator.
Variables entered should be:
DESCRIPTIVE
-variable names should be easily identified when a programmer debugs the
program.
CONSISTENT
FOLLOW RULES:
No spacing
No numbers at the beginning
No symbols at the beginning

For the Main Program:


The function main() contains two statements.
The first statement [ cout<< Hello! We are Group 5! <<endl; ] outputs the text [Hello!
We are Group 5!] on the screen. The name [cout (console output) ] designates an
object responsible for output. The less than symbols, <<, indicate that characters are
being pushed to the output stream. Finally [endl (end of line)] causes a line feed.
The last statement is return 0 which terminates the function main () and also the
program and returning a value of 0 as an exit code to the calling program. It is
standard practice to use the exit code 0 to indicate that a program has terminated
correctly.
In order for the program to start you need to click Build then click Build Solution to
check if there are no error in the program. In case there is/are error/s, scan and
recheck again the program then click Build and Rebuild Solution, respectively. If
there are no errors, Click Debug and Start Without Debugging, respectively, to
start the program. If the alignment or spacing is not in lined with your desired output,
edit it again until you come up with what you expected it to be.

Source: https://msdn.microsoft.com/en-us/library/ms235629.aspx
Programming with C++ by B.L. Juneja and Anitha Seth

You might also like