hello guys..
i tried to write this program several times.. i'am almost close..
the program is :
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, ..., and Z for 35. (Hint: use the cast operator, static_cast<char>( ), for numbers >= 10)
i didnt know how to use the static_cast well..?!?!
anyy helpp pleasee????!?!
i have an exam after 3 days
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
for(;;){
int num;
cout<<"Type a number between 0 and 35 (num>35 exits)"<<endl;
cin>>num;
if (num>=0&&num<=9) cout<<"Num: "<<num<<endl;
elseif (num>=10&&num<=35) cout<<"Letter: "<<static_cast<char>(num+55)<<endl;
else exit (-1);
}
// http://www.cplusplus.com/doc/ascii/
// Ascii table: letter A -> Hex: 41, row->4 column->1 ==> Dec: 65=16*(4)+(1)
// Your A has a value of Dec 10, the difference is 65-10=55,
// this is the offset(+55) for num
// static_cast:
// http://www.cplusplus.com/doc/tutorial/typecasting/
// static_cast<char>(num+55) similar to (char)(num+55)
return 0;
}