[Wylug-help] C++ code

Philip Wyett philipwyett at dsl.pipex.com
28 Oct 2002 19:09:24 +0000


--
On Mon, 2002-10-28 at 11:27, J Hodrien wrote:
> 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
>

Hi,

getch() is available under nix via 'ncurses'. It can be used to get the
desired effect, if you wish for key presses to be automatically
processed without CR termination.

Regards

Philip Wyett

--

Key pair can be obtained using the link below.

http://www.philipwyett.dsl.pipex.com/PhilipWyett.asc

--
--
Content-Description: This is a digitally signed message part

[ signature.asc of type application/pgp-signature deleted ]
--