I tried to make a char variable, which can store any symbol, right? So I set it to "1", which got me a bunch of errors, then I set it to 1, and it turned into this odd smiley face thing. Can someone help me?
I tried to make a char variable, which can store any symbol, right? So I set it to "1", which got me a bunch of errors, then I set it to 1, and it turned into this odd smiley face thing. Can someone help me?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I did read those. It's just like char a=1. I'm trying to get it so that when I put in cout a; I get 1, which a is, not some smiley face
Ideally int's are for numbers.Code:int i = 1; std::cout <<i <<std::endl;
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Yeah, I know, but it's a tic-tac-toe game and it would just be easier to output all the variables, and if theres an X or O in the script, then I don't have to go through the long and annoying process of changing it all. I don't know if that made sense. Imagine this is my tic-tac-toe board:
1|2|3
-------
4|5|6
-------
7|8|9
If I have a char for every "slot", then when it's empty it displays its number, so that you can input to choose that one. If it has something in it, the variable changes and no longer displays its number. As in:
X|O|X
-------
4|O|6
-------
X|X|O
This can use the same code as the last example, because it's just outputting all the variables again. I don't know if that made any sense.
Take your pick:
Code:char c = '1'; cout <<c << endl; // or c = 1; cout <<(int)c <<endl;
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
When setting the char, does it matter if you use ' or "? If it does, I feel really stupid
check my post above.Originally posted by Kespoosh
When setting the char, does it matter if you use ' or "? If it does, I feel really stupid
Yes it does matter. double quotes are for strings (char arrays), single quotes are for single chars.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Alright, thanks. Now I have another problem.
This displays 49. Why?Code:char a='1'; cout a;
think 49 is the ascii value for '1'.
Are you sure you didn't type this:
49 is the ASCII value of '1'. If you declare it as a char though, and display it, it should say 1. If not, cut and paste your whole code here for us to look at.Code:int a='1'; cout<<a;
AHA! Yes! Thank you. That fixed it.