Click here to Skip to main content
14,084,762 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Help me. I'm kinda new with c++ and I'm trying to build a simple AI program.
This is my code below. I am running it with Dev c++ and I got this [Error] expected unqualified-id before else.

can someone help?

What I have tried:

#include <iostream>
#include <cstring>

using namespace std;

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

 else if(!strcasecmp ("hi",str)){
 {
cout<<"hey there what's your name"<<end1;
goto here;
return 0;
Posted
Updated 15-Jul-18 23:02pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

the posted code is missing a open curly bracket {

if(strcasecmp ("hello",str)==0) {
    cout<< "Doing good?";
    goto here;
 }
   
Comments
AnnoyingPig 15-Jul-18 15:17pm
   
where to put???? @Bryian Tan. Master.
Thank you for reply.
Bryian Tan 15-Jul-18 15:20pm
   
This line
if(strcasecmp ("hello",str)==0)
to
if(strcasecmp ("hello",str)==0) {
AnnoyingPig 15-Jul-18 15:32pm
   
@Bryian Tan. Master sir. I Got it right Thank you so much!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You really SHOULDNT use the goto command, because it is deprecated style.

So remove the statement and write the need code or a function call at this place.
   
Comments
AnnoyingPig 16-Jul-18 8:48am
   
Thank you for helping. @KarstenK sir What are samples for function call?
jeron1 16-Jul-18 10:55am
   
Here is but one of many links.
C++ Functions[^]
AnnoyingPig 19-Jul-18 4:30am
   
okay. Thank you sir. @jeron1

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
Web05 | 2.8.190518.1 | Last Updated 16 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