Program given weird symbols, letter, characters etc.

closed account (iAk3T05o)
Compiled this code from the Programming: Practice and Principles Using C++ pdf. It runs fine but gives me weird symbols, letters and numbers in
 
  <<"char("<< c <<")\n";

Here's the complete code:

1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
double d = 0;
while (cin >> d)
{
int i = d;
char c = i;
int i2 = c;

cout <<" d = " << d
<<"\ni = " << i
<"\ni2 = " << i2
 <<"\nchar("<< c <<")\n";
Last edited on
You can find the ascii list of what various numbers represent in a char here: http://www.asciitable.com/

You can see which values you need to enter to get say, an 'a' or a '4'. The 'weird' symbol characters can be seen also on that table.

I won't comment on the program itself, since it's out of a book.
There is some strange conversions here.

a double gets stored in an int, then the int gets stored in a char, then the char gets stored in an int 'i2'. What a mess...
Topic archived. No new replies allowed.