Please help..

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cstdlib>
using namespace 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;

    else if (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;
}
Last edited on
Thankss man
thank u very much
Topic archived. No new replies allowed.