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; }
3 Antworten
+ 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.
+ 1
Thanks guys!
0
This (pokename=="no"||"No") must be substituted with this: (pokename=="no"||pokename=="No")