Task: You are given the noises made by different animals that you can hear in the dark, evaluate each noise to determine which animal it belongs to. Lions say 'Grr', Tigers say 'Rawr', Snakes say 'Ssss', and Birds say 'Chirp'.
Input Format: A string that represent the noises that you hear with a space between them.
Output Format: A string that includes each animal that you hear with a space after each one. (animals can repeat)
Sample Input: Rawr Chirp Ssss
Sample Output: Tiger Bird Snake
This is what I have tried:
#include <iostream>
#include <string>
using namespace std;
int main() {
string noises[4] = {"Grr", "Rawr", "Ssss", "Chirp"};
string animals[4] = {"Lion", "Tiger", "Snake", "Bird"};
string sounds;
getline(cin, sounds);
string sounds_filtered[sounds.size() - 1];
string word;
for (string::size_type i = 0; i < sounds.size(); i++) {
if (sounds[i] != ' ') {
word = word + sounds[i];
} else {
for (int i = 0; i<sounds.size(); i++) {
if (sounds_filtered[i] == "") {
sounds_filtered[i] = word;
break;
}
}
word = "";
}
cout << sounds_filtered;
}
return 0;
}
I think I am halfway trough the challenge, but my problem is, sounds_filtered does not contain only the words but also what it seems like pointers?
I would appreciate it if you do not give me the answer but an explanation of what I am doing wrong and were to read about it, thank you