For a program to interact with a user, it must be able to accept input. In C++, the most common way to get user input is by using the
cin
object, which stands for 'character input'. This object is used in conjunction with the extraction operator, which in code is denoted as '>>'.
In our exercise, we need to get five integers from the user. If the concept of loops has not been introduced yet, we'll ask the user to input integers one by one, like so:
cin >> firstInteger;cin >> secondInteger;cin >> thirdInteger;cin >> fourthInteger;cin >> fifthInteger;
Each line prompts the user for an input, which is then stored in a variable. It's like asking someone to drop a number into our 'boxes' one at a time. When using
cin
, remember to guide the user by printing a message before each input. This makes your program user-friendly and avoids confusion.