0

Pls explain cin

Cin

5th Aug 2021, 5:31 PM
AMAN GOYAL
6 Antworten
+ 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
5th Aug 2021, 5:38 PM
Lothar
Lothar - avatar
+ 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;
6th Aug 2021, 2:34 AM
Simba
Simba - avatar
+ 3
Cin is for get an input in c++
5th Aug 2021, 5:37 PM
MasterTom18
MasterTom18 - avatar
+ 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?
5th Aug 2021, 5:42 PM
AMAN GOYAL
+ 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;
7th Aug 2021, 5:24 AM
Vishal Pandey
+ 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
7th Aug 2021, 12:59 PM
Caushios !
Caushios ! - avatar