[Wylug-help] C++ code
J Hodrien
johnh at comp.leeds.ac.uk
Mon, 28 Oct 2002 11:27:21 +0000 (GMT)
On 28 Oct 2002, Philip Wyett wrote:
> A simple way todo the 'y/n' with a little input fault tolerance is:
>
> #include <iostream>
>
> using namespace std;
>
> int main()
> {
> char option;
>
> do
> {
> cout << "\nAre you briliant? [y/n]: ";
> cin >> option;
>
> switch(option)
> {
> case 'y':
> case 'Y':
> cout << "\nModest ain't you! :)\n\n";
> break;
> case 'n':
> case 'N':
> cout << "\nToo modest!\n\n";
> break;
> default:
> cout << "\n*** Invalid option. ***";
> cout << "\nPleae enter either 'y' or 'n'\n";
> break;
> }
> }while ((option != 'y') && (option != 'Y')
> && (option != 'n') && (option != 'N'));
>
> return 0;
> }
Although not as nice as the dos style getch/e, since you have to terminate
with a return. Playing with termios settings lets you lose that annoyance.
I'd be more helpful if I could remember...
jh
--
"I want to tell you a terrific story about oral contraception. I asked this
girl to sleep with me and she said 'no'."
-- Woody Allen