Answer:
The code for answer this written in C++ is given below:
#include <iostream>
int main() {
int number;
std::cout << "Enter an integer between 0 and 35 \n";
std::cin >> number;
if(number >= 0 && number < 10){
std::cout << "The ASCII is: " << number << "\n";
}else if(number >= 10 && number <= 35){
std::cout << "The ASCI is: " << static_cast<char>(number + 55) << "\n";
}else{
std::cout << "Enter a number between 0 and 35!";
}
}
Explanation:
The explanation of each line in the code is given below:
#include <iostream> //The library for use input and output flow, cout - cin.
int main() { //Start the logic of the program
int number; // Declare a variable which is going to store the input of the user.
std::cout << "Enter an integer between 0 and 35 \n";
/* Show in the console the message to request a number between 0 and 35*/
std::cin >> number;
/* Store the input of the user in the number variable.*/
if(number >= 0 && number < 10){
//If the number is between 0 and 10 print the number.
std::cout << "The ASCII is: " << number << "\n";
}else if(number >= 10 && number <= 35){
/*If the number is between 10 and 35 convert to ASCII, add 55 to the number because the letters in ASCII representation starts in 65*/
std::cout << "The ASCI is: " << static_cast<char>(number + 55) << "\n";
}else{
/*If the number is not between 0 and 35 display an error message*/
std::cout << "Enter a number between 0 and 35!";
}
}