+ 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; }
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;
}
0
Thanks John