Help Please!!

I am learning programming in c++ by the book "Programming Principles and Practice Using C++(2nd Edition)". I have got a problem with some code.....
Code:
char c = 'x';
int i1 = c;
int i2 = 'x';
char c2 = i1;
cout<<c<<'<<i1<<'<<c2<<'\n';

I should get the answer "x120x" but I am getting "x1764834864x"......
Please anyone help fast????
What should I do to correct it????
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    char c = 'x';
    int i1 = c;
    
    int i2 = 'x';
    char c2 = i2;
    
    // cout<<c<<'<<i1<<'<<c2<<'\n';
    std::cout << c << i1 << c2 << '\n'; 
    std::cout << c << "'" << i1 << "'" << c2 << '\n' ;
    std::cout << '\'' << c << "'" << i1 << "'" << c2 << "\'\n" ;
    std::cout << '\'' << c << " '" << i1 << " '" << c2 << "\'\n" ;
}

http://coliru.stacked-crooked.com/a/0fc04d740ee342e9
I'm just a month plus into programming. Don't know if it will help but i was thinking if your int variable being assigned a character instead of a digit might be the cause. Try assigning digits to int variable and see how it goes. Sorry if i'm talking off point.
Thanks... Ezeanata.... But i will try to do as you say......
Guys this is the final code... That runs perfectly well.....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;
inline void keep_window_open() { char ch; cin>>ch; }

int main()
{
    char c = 'x';
    int i1 = c;

    int i2 = 'x';
    char c2 = i2;

    std::cout<< c << i1<< c2 << '\n';

    keep_window_open();
    return 0;
}
Topic archived. No new replies allowed.