Created
January 13, 2022 01:08
-
-
Save GermanHoyos/9f93910cfb7f1392a53c85e90f2926ae to your computer and use it in GitHub Desktop.
Type Casting Example in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <iomanip> | |
using namespace std; | |
int main() { | |
int num; | |
cout << "Enter an integer between 0 and 35:" << endl; | |
cin >> num; | |
if (num <= 9) { | |
cout << num << endl; | |
} else { | |
//Example cin = '11'.... (97 + (11 - 10)) } = 98 which is "b" | |
cout << static_cast < char > ('A' + (num - 10)) << endl; // cast into a CHAR | |
// operator<dataType> (expression) | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment