yes and no

get yes or no from user

Page 1 of 1

6 Replies - 1449 Views - Last Post: 20 May 2001 - 06:56 PM Rate Topic: -----

#1 raptor1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-May 01

yes and no

Posted 17 May 2001 - 12:45 PM

I need help on writing a statement that can get the words yes and no from the terminal. I do not need y or n, and I know that I need an array of some sort.
Here's my code :
.
.
void do_again()
{
char yn[4];
cout<<"Would you like to play the Facto Game?
";
cout<<"Please enter yes or no and press enter.
";
do
{
cin.get (yn, 4);
cin.ignore(80, '
');
if (strcmp(yn, "yes")==0)
{
info();
}
if (strcmp(yn, "no")==0)
{
cout<<"Goodbye!
";
break;
}
if ((yn !='no)||(yn!='yes))
{
cout<<"Error
";
do_again();
}
.
.
.


(Edited by raptor1 at 2:55 pm on May 17, 2001)


(Edited by raptor1 at 3:01 pm on May 17, 2001)

(Edited by raptor1 at 3:02 pm on May 17, 2001)


Is This A Good Question/Topic? 0
  • +

Replies To: yes and no

#2 kalpeshmjoshi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 25-April 01

Re: yes and no

Posted 17 May 2001 - 08:18 PM

if ((yn !='no)||(yn!='yes))
{
cout<<"Error
";
do_again();
}

You have made mistake here, use strcmp and proper syntax
if (strcmp(yn,"no") && strcmp(yn,"yes"))
[color=blue]

Was This Post Helpful? 0
  • +
  • -

#3 raptor1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-May 01

Re: yes and no

Posted 18 May 2001 - 12:27 PM

Yes, I added that code, but it still gives me one error. I also declared char yn[4] as a global variable.
Here's the code :
.
.
.
if (strcmp(yn,"no"))&&(strcmp(yn,"yes")
{
cout<<"Error
";
do_again();
}
.
.
.
It gives me the error :
'missing ";" before "&&"


What's going on???

(Edited by raptor1 at 2:31 pm on May 18, 2001)

(Edited by raptor1 at 2:32 pm on May 18, 2001)

Was This Post Helpful? 0
  • +
  • -

#4 Null and Void  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 29-April 01

Re: yes and no

Posted 18 May 2001 - 02:05 PM

That should be
strcmp( string1,string2 ) == 0


to check if a string is exactly equal to another string. So, to test if the string is "yes", you'd do this:
if( strcmp(inputstring, "yes") == 0 ) {
  // IS YES
}


Was This Post Helpful? 0
  • +
  • -

#5 Null and Void  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 29-April 01

Re: yes and no

Posted 18 May 2001 - 02:07 PM

Also, make sure you include string.h.
Was This Post Helpful? 0
  • +
  • -

#6 Paradox  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 432
  • Joined: 03-March 01

Re: yes and no

Posted 20 May 2001 - 04:53 PM

Just a tip:
When using code, uncheck the emoticons option in the new post screen.  It will make sure that ;) is not converted to a smilie
Was This Post Helpful? 0
  • +
  • -

#7 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: yes and no

Posted 20 May 2001 - 06:56 PM

but it looks so cute in the code... lol
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1