+ 1

Jungle Camping challange problem

I wrote the code in C++ and 3 out of 5 tasks were completed yet 2 failed? I don't get how so if anyone can figure it out please tell me where I've made a mistake. Here's the code: #include <iostream> #include <string> using namespace std; int main() { int i; string a,b,c,d,sounds[3]; a="Grr"; b="Rawr"; c="Ssss"; d="Chirp"; cin>>sounds[0]; cin>>sounds[1]; cin>>sounds[2]; for (i=0;i<=2;i++) { if (sounds[i]==a) cout<<"Lion "; if (sounds[i]==b) cout<<"Tiger "; if (sounds[i]==c) cout<<"Snake "; if (sounds[i]==d) cout<<"Bird "; } return 0; }

29th Dec 2019, 9:30 PM
Beks
Beks - avatar
3 Respostas
+ 1
Your code works only for three sounds. But I guess some input strings contains more.
29th Dec 2019, 9:50 PM
Denise Roßberg
Denise Roßberg - avatar
+ 4
Apparently there were more than 3 sounds so i put 4 more and it worked! Thank you so much for your help!
29th Dec 2019, 10:55 PM
Beks
Beks - avatar
0
Beks Your welcome :)
29th Dec 2019, 10:56 PM
Denise Roßberg
Denise Roßberg - avatar