0

Why doesnt this code skip the index if something other than no is entered?

#include <iostream> using namespace std; #include <string> int main() { string pokename; int p; cout<<"Type the name of a pokemon. if you want to type its index number instead type 'no.'"<<endl; cin>>pokename; if(pokename=="no"||"No"){ cout<<"Type the index number"<<endl; cin>>p; } if(pokename=="pikachu" || pokename=="Pikachu" || p==5){ cout<<"electric"; } else if(pokename=="golduck" || pokename=="Golduck" || p==4){ cout<<"water"; } else{ cout<<"I don't know that pokemon"; } return 0; }

20th Aug 2016, 3:15 AM
Jack Gruber
Jack Gruber - avatar
3 Respuestas
+ 1
In the first condition change it to || pokename=="No". I suspect "No" on its own is evaluating to something greater than 0 thus it always satisfies the OR condition.
20th Aug 2016, 3:23 AM
Ahkrin
+ 1
Thanks guys!
20th Aug 2016, 11:42 AM
Jack Gruber
Jack Gruber - avatar
0
This (pokename=="no"||"No") must be substituted with this: (pokename=="no"||pokename=="No")
20th Aug 2016, 6:36 AM
Tamas Szekffy
Tamas Szekffy - avatar