+ 2

Why this is wrong?

#include <iostream> using namespace std; int main() { char noisy,Grr,Rawr,Chirp,Sss; cout<<"\nType which sound are heard(Grr,Sss,Rawr and Chirp):"; cin>>noisy; if(noisy==Grr) cout<<"\nThe animal is Lion"; if(noisy==Rawr) cout<<"\nThe animal is Tiger"; if(noisy==Chirp) cout<<"\nThe animal is Bird"; if(noisy==Sss) cout<<"\nThe animal is Snake"; return 0; }

31st Mar 2020, 9:04 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
2 odpowiedzi
+ 1
animals sound are strings not character. #include <iostream> using namespace std; int main() { string noisy; //cout<<"\nType which sound are heard(Grr,Sss,Rawr and Chirp):"; cin>>noisy; if(noisy=="Grr") cout<<"Lion"; if(noisy=="Rawr") cout<<"Tiger"; if(noisy=="Chirp") cout<<"Bird"; if(noisy=="Sss) cout<<"Snake"; return 0; }
31st Mar 2020, 11:17 AM
John Robotane
John Robotane - avatar
0
Thanks John
31st Mar 2020, 11:25 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar