char equals an int??

I dont even know how to word this but... I am trying to make
the program recognize a char and convert it to an int. I want to make the user decide whether the dog is tall or short and depending on the user input it would give cat an int value. What I had in mind for example was, if dog equals Tall or tall then cat equals 1. If dog equals Short or short then cat equals 2. How would I incorporate that in to the code below?

1
2
  if (dog == 't' || dog == 'T')  
  if (dog == 's' || dog == 'S')


is this even possible?
Last edited on
You know a char is just a single character right? e.g. 'a' or 'j' or '&'. If you really want the user to put in an entire word, you will need to use strings. It is done like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
#include <string> //Include the string library. 

using std::string; 
using std::cin; 
using std::cout; 

int main()
{
    string s = ""; //Declare a string s. 
    cout << "Is the dog tall or short?\n";
    cin >> s; //Get word from user and store it in string s. 
    if(s == "Tall") //Strings go inside double quotes. 
    {
        dogsize = 2; 
    }
    else if(s == "short")
    {
        dogsize = 1; 
    }
return 0; 
}
You are asking about char and int

However, none of the code you posted specifies what the type of anything is (with the exception of short, which is a built-in type).

It looks like you are referring to character strings? In which case they should be quoted, "tall" or maybe tall is the name of a variable? And what is dog, a variable of some type, or a string?
Thanks guys, I caught the mistake I did because I meant to enter in 't' or 'T' and 's' or 'S' for tall and short char when I typed my question out. It answered my question tho, thanks again!
Topic archived. No new replies allowed.