need a little help on an easy problem

cpulocksmith's Avatar, Join Date: Jul 2008
Skilled contributor
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();
}
0
jayaraj_ev's Avatar, Join Date: Aug 2007
Go4Expert Member
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")

Last edited by jayaraj_ev; 23Mar2009 at 14:14..
0
jayaraj_ev's Avatar, Join Date: Aug 2007
Go4Expert Member
Sorry just compare using

strcmp or else it will check for ptr address validation.
0
cpulocksmith's Avatar, Join Date: Jul 2008
Skilled contributor
ah, thank you jayaraj_ev. i know it would be easy i just never read how to compair two strings, thanks