It is easy to do by using cin>>.
See the example below:
#include “iostream.h”
#include “conio.h”
main()
{
int x;
cout<< ”Insert a number: ”;
cin>> x;
cout<<” The number you inserted is: ” << x;
getch();
}
See the picture below as the result:
With cin>>; The program will ask the user to insert a number, and the program will fill the value inserted by user to the variable, then print it to screen because of cout<< x syntax. So the number shown on the screen is depend on the number inserted by user.
We can use the same way to a char variable. Just change int x; become char x;
0 comments:
Post a Comment