Saturday, August 30, 2014
Browse »
home»
a
»
c
»
from
»
get
»
how
»
input
»
program
»
simple
»
to
»
user
»
How to get input from user a simple C program
How to get input from user a simple C program
A simple C++ program to get integer from user:-
Today i will teach you, how to get input from user, note we are taking here only an integer value from user like 1,2,3... not in fractional or decimal from at the end of this tutorial i will teach you to get decimal input from user.
Now to get an input from user, there is a command cin which is used to get any type of integer from user.
Starting from the first line in main function there is a command
int x int is use for integer and x is any variable to carry an input from user, means x is variable of data type integer.
Now moving to next line cout used to print on screen, which i had already discuss in previous tutorial.
Moving to next line there is a command cin>>x this command is the main command to get data from user, it will get data from user and store in variable x, you can use any variable you want.
Now its time to show the input on screen we used cout statement then text to display which is place in inverted commas after that or you can use in next line x which is variable in which data is stored.
Then closing the main function.
This is all about getting input from user.
Now there is another thing if you want to get data which is in decimal form then you have to change the data type which previously i used int for integer, for decimal data type you have to used float then a variable name.
You should try this code on your compiler by simply changing the data type from int to float.
Thats all for today, hope you understand very well, if you found any difficulty please let me know through comments.
Today i will teach you, how to get input from user, note we are taking here only an integer value from user like 1,2,3... not in fractional or decimal from at the end of this tutorial i will teach you to get decimal input from user.
Now to get an input from user, there is a command cin which is used to get any type of integer from user.
Starting from the first line in main function there is a command
int x int is use for integer and x is any variable to carry an input from user, means x is variable of data type integer.
Now moving to next line cout used to print on screen, which i had already discuss in previous tutorial.
Moving to next line there is a command cin>>x this command is the main command to get data from user, it will get data from user and store in variable x, you can use any variable you want.
Now its time to show the input on screen we used cout statement then text to display which is place in inverted commas after that or you can use in next line x which is variable in which data is stored.
Then closing the main function.
This is all about getting input from user.
Now there is another thing if you want to get data which is in decimal form then you have to change the data type which previously i used int for integer, for decimal data type you have to used float then a variable name.
You should try this code on your compiler by simply changing the data type from int to float.
Thats all for today, hope you understand very well, if you found any difficulty please let me know through comments.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment