Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   need a little help on an easy problem (http://www.go4expert.com/forums/little-help-easy-t16629/)

cpulocksmith 23Mar2009 06:56

need a little help on an easy problem
 
ok well this is kinda dumb and i run into it alot. i always find a way around it but i dont know how to solve it. here is the code, it is a part of some stupid thing i am making please help me out.
the problem is that when even you enter "command" it always outputs the response for help. please help. lol.

the code
Code:

cin>>commands;


//will output the help info
if (commands == "help" || 'h'){
cout<<"help files"<<endl;
cout<<"\n\n\n ok?"<<endl;
cin>>a;
gameplay();
}

if (commands == "dive" || 'd'){
cout<<"how far?"<<endl;
cin>>varDepth;
comments = "you have dove down "; varDepth;
currentDepth = currentDepth + varDepth;
gameplay();
}


jayaraj_ev 23Mar2009 14:04

Re: need a little help on an easy problem
 
Hi,
The reason is simple..
ur trying to compare ( (commaand == "help") || 'h')
which is always true.try to compare it with

(command== "help") ||
(command == "h")

jayaraj_ev 23Mar2009 14:23

Re: need a little help on an easy problem
 
Sorry just compare using

strcmp or else it will check for ptr address validation.

cpulocksmith 23Mar2009 17:25

Re: need a little help on an easy problem
 
ah, thank you jayaraj_ev. i know it would be easy i just never read how to compair two strings, thanks


All times are GMT +5.5. The time now is 05:55.