0

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...";
}

Edited by Nick Evan: Added CODE tags

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by WaltP
1

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.

Edited by pyTony: fixed formating

Comments
code tags comment :)
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.