New to c++ and static_cast<char>()

  c++

So I’m in college right now and I have this lab that wants me to make a code that inputs an integer and outputs a corresponding letter, I was able to get the code to work but it wants me to use static_cast() for 1-9
"
Write a program that prompts the user to input an integer between 0 and 35. The prompt should say Enter 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: For numbers >= 10, calculate the ACSII value for the corresponding letter and convert it to a char using the cast operator, static_cast().)"

and here is what I have.

 #include <iostream>

using namespace std;

int main() 
{
 int num;

 cout << "Enter an integer between 0 and 35: ";
 cin >> num;
 cout << endl;

 switch(num)
 {
   case 0:
    cout << "0";
      break;
   case 1:
    cout << "1";
      break;
   case 2:
    cout << "2";
      break;
   case 3:
    cout << "3";
      break;
   case 4:
    cout << "4";
      break; 
   case 5:
    cout << "5";
      break;
   case 6:
    cout << "6";
      break;
   case 7:
    cout << "7";
      break;
   case 8:
    cout << "8";
      break;
   case 9:
    cout << "9";
      break;
   case 10:
    cout << "A";
    break;
   case 11:
    cout << "B";
   case 12:
    cout << "C";
   case 13:
    cout << "D";
   case 14:
    cout << "E";
   case 15:
    cout << "F";
   case 16:
    cout << "G";
   case 17:
    cout << "H";
   case 18:
    cout << "I";
   case 19:
    cout << "J";
   case 20:
    cout << "K";
   case 21:
    cout << "L";
   case 22:
    cout << "M";
   case 23:
    cout << "N";
   case 24:
    cout << "O";
   case 25:
    cout << "P";
   case 26:
    cout << "Q";
   case 27:
    cout << "R";
   case 28:
    cout << "S";
   case 29:
    cout << "T";
   case 30:
    cout << "U";
   case 31:
    cout << "V";
   case 32:
    cout << "W";
   case 33:
    cout << "X";
   case 34:
    cout << "Y";
   case 35:
    cout << "Z";
 }
    // Write your main here
    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT