0
Pls explain cin
Cin
6 Respostas
+ 7
AMAN GOYAL ,
i have seen that you have started already with c++. 'cin' is described in lesson 7.1 (basics) and used to take input from user and store it to a variable.
for further questions please be a bit more descriptive. please also specify the programming language you are going to use in a tag.
thanks
+ 5
You missed to define variable x.
Also, int b havent been assigned a value yet. So, you're adding together a non-existant value with variable a and storing them in sum. But, if after cin is used to assign a value to b, you can assign the sum of them to the sum variable and print it, it will output the value because the value actually exists.
So, your code needs to be like this,
int a=15;
int x;
cin>> x;
int b = x;
int sum =a+b;
cout <<sum;
+ 3
Cin is for get an input in c++
+ 3
Like this
Int a=15
Int b=x
Cin>> x
Int sum =a+b
Cout <<sum
(Like I used x as cin it mean I change the value x any time??)
And why this code is not working?
+ 3
For formatted input operations, cin is used together with the extraction operator, which is written as >> (i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored. For example:
int age;
cin >> age;
+ 2
It is easy, cout (c+out) used for output, cin (c+in) used for input. By cin you can take a value from user and store it in a variable