Click here to Skip to main content
14,115,780 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
How do I make a user like type in "I'm feeling good" and it reads the "good" part in which the program would respond to
"I see, That's great to hear from you"

My code is like when i type in "jasdhagood" or anything other than the 'good' itself would respond to blank.

sample:

User:I'm good
Program:I see, That's great to hear from you

Anyone, help me?

What I have tried:

#include <iostream>
#include <cstring>
#include <String>

using namespace std;



void replyy(){
	string y;
	cin>>y;
	cout<<"I see your name is "<<y<<endl;
	
	
}

void goodornot(){
char responds[50];
  here:cin>>responds;
	
	if(strcasecmp("good",responds)==0){
	cout<<"I see, That's great to hear from you";
	}


else if(!strcasecmp("great",responds)){
	cout<<"I see, Feeling great!"<<endl;
}

}

int main(){
  char str[50];
  char understanding[50];
  char relation[50];
  here:cin>>str;
  
  if(strcasecmp ("hello",str)==0){
  
  cout<< "Doing good?";
  goodornot();
}

 else if(!strcasecmp ("hi",str)){
 
cout<<"hey there what's your name"<<endl;
 replyy();

}

else if(!strcasecmp ("sad",str)){
 relation==str;
 understanding==relation;
 
cout<<"Don't be sad.'"<<understanding;
goto here;


return 0;
}}
Posted
Updated 19-Jul-18 20:25pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

   
Comments
AnnoyingPig 20-Jul-18 1:20am
   
I see. Thank you for the information. Is it applicable with c++?
Gerry Schmitz 20-Jul-18 14:39pm
   
It's applicable to any (.NET) "managed" language: C#; VB.NET; C++; ...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

What you want is to find some text into other text. Use the string::find functions. The string class has also other nice functions.

I would use case insenstive comparison.

Take care of compiler warnings, because the show you problems. Assigning a string to char buffer shouldnt work!!!
   
Comments
AnnoyingPig 20-Jul-18 13:36pm
   
:D okay, gonna study this now! Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 20 Jul 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100