If statement question and answers

What did I do wrong with this code, it only prints out the first cout no matter what you type in


#include <iostream>
#include <string>

using namespace std;
int main()
{
string cat;
string dog;
string penguin;
string teenager;
string turkey;

cout << "enter one of the following animals to find out what they think on a day to day basis. (dog, turkey, cat, penguin, or teenager)";

if (cin >> cat)
{
cout << "you will die and soon I will rule the world hahaha!";
}

else if (cin >> dog)
{
cout << "Squirrel";
}
else if (cin >> turkey)
{
cout << "Kill me!!!";
}
else if (cin >> penguin)
{
cout << "waddle waddle waddle";
}
else if (cin >> teenager)
{
cout << "Why is everybody looking at me : (";
}
return 0;
}



cin >> cat

This code fetches a word from the keyboard and stores that word in the variable "cat".

I expect it's not at all what you meant. I think you meant this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>

using namespace std;
int main()
{
  string userInput;
  cout << "enter one of the following animals to find out what they think on a day to day basis. (dog, turkey, cat, penguin, or teenager)";

  cin >> userInput;

  if (userInput == "cat")
  {
    cout << "you will die and soon I will rule the world hahaha!";
  }
  else if (userInput == "dog")
  {
    cout << "Squirrel";
  }
  else if (userInput == "turkey")
  {
    cout << "Kill me!!!";
  }
  else if (userInput == "penguin")
 {
    cout << "waddle waddle waddle";
  }
  else if (userInput == "teenager")
 {
    cout << "Why is everybody looking at me : (";
  }
return 0;
}


Thanks so much, that makes a whole lot of sense and so much easier
Topic archived. No new replies allowed.