Basic Input and Output Statement
After familiarizing with the special characters and its function, it is much better to understand the concept on how to input and output such statement.Learn first the definition and purpose of each statement.
The “cout -
statement”
Ø Is also
called standard output statement or console output.
Is used for displaying the output into the
monitor.
Ø
Its
syntax is as follow:
cout << “variable”;
Ø
the symbol “<<” is called insertion
operator.
Example:
1.
cout << “Programming is Fun!”;
2.
cout << “Hello World!”;
3.
cout
<< “Enter your name\n”;
4.
cout << “Hi” << name << endl;
The “cin - statement”
Ø is
also called standard input statement or console input.
Is
used to accept the value of the variable.
Waits
for the input to be entered from the
keyboard.
Ø Its
syntax is as follow:
cin >>
variable;
Ø The
symbol “>>” is called extraction operator.
Example:
1.
cin >> name;
2.
cin >> number of bulbs;
3.
cin >> number of lightbulb << serial
number;
Sample Program using Input and Output Statement
#include <iostream.h>
using namespace std;
int main ()
{
int name;
cout << “Welcome to Dev C++!
”;
cin >> name;
return 0;
}
The output would be like:
Welcome to Dev C++! Keybo
Programming Tip:
End each program with \n and endl
It is a good
idea to output a new-line instruction ( \n and endl ) at the end of every program. If the last
item to be output is a string, then include a "\n "at he end of every string; if
not output and "endl" as the last action your program
No comments:
Post a Comment