1: //display_sequences.cpp 2: //Displays sequences of both characters and integers in ranges chosen 3: //by the user. Illustrates a count-controlled for-loop, as well as 4: //sequential loops and some C-style casts. 6: #include <iostream> 7: #include <iomanip> 8: using namespace std; 10: int main() 11: { 12: cout << "\nThis program displays both character and integer " 13: "sequences in user-chosen\nranges. For characters, it " 14: "assumes the user knows (from prior experience)\nthe " 15: "internal integer codes for the first and last character " 16: "of the required\nsequence.\n\n"; 18: int first, last; //Range boundaries 19: int i; //Loop control variable 21: cout << "First, characters in \"increasing\" order.\nEnter the " 22: "internal integer codes for the first and last characters " 23: "you want:\n"; 24: cin >> first >> last; cin.ignore(80, '\n'); 25: for (i = first; i <= last; i++) 26: cout << char(i); 28: cout << "\n\nNow, integers in decreasing order.\n" 29: "Enter the first and last integers you want (larger first):\n"; 30: cin >> first >> last; cin.ignore(80, '\n'); 31: for (i = first; i >= last; i--) 32: cout << i << " "; 34: cout << "\n\nFinally, characters marching down the display to the " 35: "right in decreasing order.\nEnter the internal integer codes " 36: "for the first and last characters you want:\n"; 37: cin >> first >> last; cin.ignore(80, '\n'); 38: int indentLevel = 0; 39: for (i = first; i >= last; i--) 40: { 41: cout << setw(indentLevel) << "" << char(i) << endl; 42: indentLevel++; 43: } 44: cout << endl; 45: }