0

Cin

int time, rime; cin >> time >> rime; Input is 9: 8 Why doesnt rime take 8 as input?

27th Jan 2020, 5:05 PM
Zohal
Zohal - avatar
7 Réponses
+ 4
You have to take Input in seperate line on Sololearn Playground. like this 9 8
27th Jan 2020, 6:39 PM
A͢J
A͢J - avatar
+ 3
If you try to read in something that doesn't work - like a char into an int - the cin object is set to 'fail'. In that case you first have to use the cin.clear() method to reset it to normal.
27th Jan 2020, 7:24 PM
HonFu
HonFu - avatar
+ 2
Seems, cin is made to detect mistakes instead of ignoring them, but I don't know the details myself. I'd recommend (also to myself) to google cin and study it thoroughly.
27th Jan 2020, 8:29 PM
HonFu
HonFu - avatar
+ 1
A J No u got it wrong Input is not 9 8 or 9 8 Input is 9: 8 Or 9: 8
27th Jan 2020, 6:45 PM
Zohal
Zohal - avatar
+ 1
Zohal I think it's happening because of 9: . If we take input as 9 then it's taking 8 as input otherwise 0 is coming. Let's see the reply of people who know c++ well.
27th Jan 2020, 7:19 PM
A͢J
A͢J - avatar
0
HonFu If I read a char into an int, shouldnt it save the Ascii code instead?
27th Jan 2020, 8:21 PM
Zohal
Zohal - avatar