User Input Display in C++

User Input in C++

Today i will teach how to take input form user and how to display it on screen.There are two types of inputs  1 is User input at run time or real time input and the second one is the input that is already written in the code . Now i will take input form user at run time and that input will be displayed on the screen. So the the function or you can also call Keyword used for taking input from user at run time is “cin>>” as I have already described that the C++ is case sensitive language so  be aware . If your write CIN>> instead of cin>> that the compiler will show an error what is CIN>> because complier don,t know the meaning of CIN>> . The header file that contains the information of cin>> is “#include<iostream.h>”.

In the below written code the computer will ask you to write your age and after that press enter then your written age will be shown on the screen.

So here is the code

The line number 1 is header file #include<iostream.h>  which contains the information of the “cin>>”

The line number 2  is also a header file #include<conio.h>  which contains the information of the getch();  , clrscr();

getch();  is function we use it to take one single character from user ,but here we use it for displaying our output.

clrscr();  is also a function used for  clearing the previous screen if something is already written on the screen before execution of the this function that all will be erased from screen.

The line 3 is  void   main()  it is actual part of the program from where all execution will start.

The line 4 is {  it is open curly bracket which indicates that from here the code or program is starting.

The line 5 is clrscr();  which is described above .

The line 6 is  int age;   this will create an integer variable in the memory of name age where we will store the input that the user will give.

The line 7 is  cout<<“Please Enter Your Age:”;  This will print the statement on the screen which is written in the double quotes .

The line 8 is cin>>age;  The will take the input from user and that input will be stored in the variable whose name is age.

The line 9 is cout<<“Your age is”<<age;   This will print the statement which is written in double quotes as well as the age which is user given ;

The line 10 is getch();   here we will it to view the output .

The line 11 is }   which is close curly bracket which indicates that here is the end of the program.

So this was the program to take input form user and display it on the screen, hope you are now able to take any input form user and display it on screen.

Leave a Reply

Your email address will not be published. Required fields are marked *