Cin Age // Read in Age: // Process It
Cin Age // Read in Age: // Process It
// process it
}
The sentinel value for age is -1. Since age is a variable, it must be
previously declared.
How about? Int age = -99
This will work but a more elegant approach is to use a priming read.
This means to read the first data value immediately before the while
loop.
The above code, using a priming read, now looks like:
int age;
cin >> age;
//priming read
while(age != -1)
{
cin >> age;
}
If the first value of age is -1, then we dont enter the while loop. This
part is correct.
However, the code is incorrect as it does not process the first age
value.
cin >> age;
Write a code to read and echo the characters from one line of
than input file. (quiz #2)
How do you get the next character from a buffer? we use dot get.
What are we going to store it in? a char variable.
While (____ != )/n
Whats the process? Simply print the value
After done processing? get the next char value, we are going to use
the .getvalue
What goes next? close that bracket.
*read and echo simply means read and print.
There are 4 kinds of loop?
1ST QUESTION: Do you know the number times the loop will iterate.
2nd QUESTION: Is there a special value marking the end of the data?
(you stop looping when you read /endl)
Sentinel loop
Read