I’ve started learning C++. Here’s my simple problem. I have a code:
int main() {
int number;
cout << "Input number: ";
cin >> number;
cout << "here is hex = 0x"
<< hex << number << endl;
}
I’m using Visual C++. I think the point of this program is easy, user enters some number and program converts it to hex value. But when I enter some number and hit enter, console window just closes. How to display hex inside console window?
Try to include
cstdliband addsystem("PAUSE");to your main:That’s it, happy programming 😉
Instead of pausing you could also use
getch()fromconio.h. This waits for a key, so the console window wont close until you hit any key…From the comments, to get
PIin C++ just add the following to your header:and you’ll have access to the variable
M_PI🙂