954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

my string is not inputing...

This is a program which i am making of a quiz in which there are lifelines for helping the user solve his question. this function is to chose from whichever lifeline the user wants to chose. but my problem is that it is not inputing the string i.e not using the "cin.getline(maxy, 30, '\n' );". Please help...

void whichlifeline()
      {
           char maxy[30];
           int integer;
           cout<<"\n\nDo you want to use any lifeline?(1 for Yes/2 for No)"<<endl;
           cin.getline ( maxy, 30, '\n' );  
           if((strcmp(maxy,"yes")) || (strcmp(maxy, "yes")))
           {
                        cout<<"Which lifeline do you want to use?\n1 Audience poll\n2    Double Dip\n3 50-50\n";
                        cin>>integer;
                        if(integer==1)
                        audiencepoll();
                        else if (integer==2)
                        doubledip();
                        else if (integer==3)
                        fiftyfifty();
           }
           else
           cout<<"PROCEED...";
}
Attachments new.bmp (826.93KB) output.bmp (97.32KB)
Arjunah
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Your problem is that you're not using strcmp correctly. Refer to C++ Reference strcmp .

Correct if-statement is:

if(strcmp(maxy,"yes")==0){
do something;
}
else{
do something else;
}


Also, please use [CODE] tags next time.

beaute
Newbie Poster
14 posts since Dec 2008
Reputation Points: 27
Solved Threads: 0
 

Your problem is that you're not using strcmp correctly. Refer to C++ Reference strcmp .

Correct if-statement is:

if(strcmp(maxy,"yes")==0){
do something;
}
else{
do something else;
}

Also, please use [CODE] tags next time.

now it is not inputing string and executing both if and else statements...

Attachments now._._._.bmp (104.64KB)
Arjunah
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

How do you know it's not inputting the string? Immediately after you try to input it, display it. Don't just assume something is wrong. Prove it.

And it's impossible to be "executing both if and else statements". It can't be done.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: