[[lesson_9_get_yn.cpp]] Rescued by C++ Reloaded

Route:


[user02@FC4 Lesson09]$ cat -n get_yn.cpp
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int done = 0; // Set to true when Y or N is encountered 7 char letter; 8 9 while (! done) 10 { 11 cout << "\nType Y or N and press Enter to continue: "; 12 cin >> letter; 13 14 if ((letter == 'Y') || (letter == 'y')) 15 done = 1; 16 else if ((letter == 'N') || (letter == 'n')) 17 done = 1; 18 else 19 cout << '\a'; // Sound the speakers bell for 20 // invalid character 21 } 22 cout << "The letter you typed was " << letter << endl; 23 24 return 0; 25 }
[user02@FC4 Lesson09]$ g++ -o get_yn get_yn.cpp
[user02@FC4 Lesson09]$ ./get_yn

Type Y or N and press Enter to continue: y
The letter you typed was y
[user02@FC4 Lesson09]$ ./get_yn

Type Y or N and press Enter to continue: a

Type Y or N and press Enter to continue: No
The letter you typed was N
[user02@FC4 Lesson09]$
lesson_9_get_yn.cpp, Rev. 1, Last changed on 2005-08-10 03:45, 281 page hits
Wiki hosted for free at wikihost.org || RSS-Feed || GeboGebo 1.3.3 || 00.194 seconds || || PAGERANK TOOLS