Monday, May 24, 2010

A C++ Question ? How to read a 2 letter character in an input.?

I have to create a program that reads in characters until the user enters the correct two- character sequence= (cs) to open door.





Sample Data:


cs = Door opens





ccs=Door opens





fkcds=Door doesn't open





kasfcsgd=Door opens





I have to use While Loop. but I need Answers what to put in -





My code:


/*====================================...





#include %26lt;iostream.h%26gt;





void main()


{


char ch;


int done;





cout %26lt;%26lt; endl %26lt;%26lt; "You have before you a closed door." %26lt;%26lt; endl;





while(done)


{


cout%26lt;%26lt;"Enter a sequence of letters: ";


cin%26gt;%26gt;ch;





if()


}





cout %26lt;%26lt; "The door opens. Congratulations!" %26lt;%26lt; endl;


}





/*====================================...





It is not Finished, It is just a shell I made to help.

A C++ Question ? How to read a 2 letter character in an input.?
just add another variable...one that keeps track of a "c" and one for an "s"...the better way is to use strcmp(), but be careful of hidden null characters at the end which may or may not be an issue.


No comments:

Post a Comment