how to test a type int as a char
-
I would like to know if there is a way to store a character in a type int variable. I would still like the variable to be able to store integers, but if a certain charcter is entered I would like the program to do something else. example: int number; cout<<"Enter a number: "; //This is where I would like to enter 'c' cin>>number; if(number=='c') { ... } else { ... } can you please help? dudeoffrance
-
I would like to know if there is a way to store a character in a type int variable. I would still like the variable to be able to store integers, but if a certain charcter is entered I would like the program to do something else. example: int number; cout<<"Enter a number: "; //This is where I would like to enter 'c' cin>>number; if(number=='c') { ... } else { ... } can you please help? dudeoffrance
dudeoffrance wrote: if(number=='c') Which is equivalent to:
if (number == 99)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
I would like to know if there is a way to store a character in a type int variable. I would still like the variable to be able to store integers, but if a certain charcter is entered I would like the program to do something else. example: int number; cout<<"Enter a number: "; //This is where I would like to enter 'c' cin>>number; if(number=='c') { ... } else { ... } can you please help? dudeoffrance
well yes u can..... character is just i byte where as and integet is four bytes..... by doing the above code.....that u have listed.....u will get the ascii value of the character...... search for the ascii table....it will give the corresponding values for a character variable..... in ur case the character 'c' has an intef=ger value of 99..... cheerz.....:-D "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13