I'm using Dev-C++ on Windows. I'm trying to "Write a program that prompts the user to input an integer between 0 and 35. If the number is less than or equal to 9, the program should output the number; otherwise, it should output A for 10, B for 11, C for 12, ..., and Z for 35. (Hint: Use the cast operator, static_cast<char>() for numbers >= 10."

The program compiles, but when I run it, the command window closes right after I enter an integer. Please tell me what I have to add to my code to get it working.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
int num;

cout << "Enter a number between 0 and 35: ";
cin >> num;
cout << endl;

if (num <= 9)
cout << num << endl;
else if (num >= 10 && num <= 35)
cout << static_cast<char>('A' + (num - 10)) << endl;
else if (num < 0 || num > 35)
cout << "You have entered an incompatible number." << endl;

return 0;

Thank you
the window closes because it quickly prints the output then the program ends (once the end of main is reached).

Common newb problem. There's a whole sticky topic on it here:
Wow that was so simple. Thank you!
Topic archived. No new replies allowed.