1: //simple_io.cpp 2: //Illustrates output of user prompts, with corresponding input 3: //and output of integer, real and character values. 5: #include <iostream> 6: using namespace std; 8: int main() 9: { 10: cout << "\nThis program illustrates the input and output of " 11: "integer (int), real (double),\nand character (char) values. " 12: "In each case, note the cursor position when the\nprogram is " 13: "waiting for input.\n"; 15: //Input, and then output, a single integer value. 16: //Value is entered immediately following the prompt, with a single 17: //space between the end of the prompt and the start of the value. 18: int someInteger; 19: cout << "\nEnter an integer value here: "; 20: cin >> someInteger; 21: cout << "The integer you entered was " << someInteger << ".\n"; 23: //Input, and then output, a single floating point (real) value. 24: //Value is entered at the start of the line following the prompt. 25: double someReal; 26: cout << "\nEnter a real number value here:\n"; 27: cin >> someReal; 28: cout << "The real number you entered was " << someReal << ".\n"; 30: //Input, and then output, two character values. Tab characters 31: //are used to line up the entry positions of the two input values. 32: char firstChar, secondChar; 33: cout << "\nEnter a character value here:\t\t"; 34: cin >> firstChar; 35: cout << "Enter another character value here:\t"; 36: cin >> secondChar; 37: cout << "The first character entered was " << firstChar << ".\n"; 38: cout << "The second character entered was " << secondChar << ".\n"; 39: cout << endl; 40: }