Do these following input data lines work correctly?

1)

User Input: 24 25 26

int first, second, third;
cin >> first >> second >> third;

2)

User Input: 24.4 25.5 26

double fourth, fifth, sixth;
cin >> fourth >> fifth >> sixth;

3)

User Input: 24.4 25.5 26.6

int seventh, eighth, ninth;
cin >> seventh >> eighth >> ninth;

4)

User Input: 23.4 24.5

double tenth, eleventh, twelfth;
cin >> tenth >> eleventh >> twelfth;
Yes, they work respectively. Remember though when you point floating points into ints the data could be off.
Last edited on
Scenario 3 won't work.
why wont 3 not work? and why do they work respectively? the reason I do not get it is because the user is inputting 3 different numbers, and then saying the integer is the seventh, eighth, ninth....or whatever scenario it is. then saying the input is seventh>>eigth>>ninth or whatever. what do the numbers have to do with the integer input?
What happens in scenario 3 is that 24 is extracted from the stream into seventh leaving ".4 25.5 26.6" in the stream. The next extraction into eighth fails because there is no way to extract an integral type from a decimal point. This puts cin into a fail state so it returns immediately on the third extraction without attempting to actually extract anything into ninth.

Topic archived. No new replies allowed.