C++ a simple question

My code is below :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include <iostream>
 using namespace std; 

main() { 

bool a;
 int x; 

cout<< "Please enter number higher than 10" << endl << cout<<"If the number is higher than 10 you'll see 1 else 0";
 cin>>x; 

a=(x>10); 

cout<<a; 

cin>>x; 

} 


On the output I saw :
Please enter number higher than 10
0x486a08If the number is higher than 10 you'll see 1 else 0

Why do I see 0x486a08 ? what is wrong on my code ?
Thanx





you have to use an if and an else statement, ie:
1
2
3
4
5
6
int a;
    cin>>a;
    if(a>10)
        cout<<'1';
    else
        cout<<'0';
Last edited on
closed account (LNboLyTq)
Hi saner,

cout<< "Please enter number higher than 10" << endl << cout <<"If the number is higher than 10 you'll see 1 else 0";

This is something unusual to see. You are actually using std::cout to print out std::cout.

If you write it in two lines, that will solve your problem.
1
2
cout<< "Please enter number higher than 10" << endl;
cout << "If the number is higher than 10 you'll see 1 else 0";


Andy.

rossy23 wrote:
you have to use an if and an else statement,

Not true. It's perfectly valid to evaluate a boolean expression and assign the result to a bool.
Last edited on
Hello saner,

Actually closed account has the answer. Once I changed line 9 into 2 lines it worked fine.

Andy
Topic archived. No new replies allowed.