Results 1 to 2 of 2

Thread: changing chars by using integers in variables

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    1

    changing chars by using integers in variables

    char newChar;
    int amount = 2;

    newChar = 'A' + 2; // gives me C, which is great

    newChar = 'A' + amount; // nothing, i get an error ???



    The error:

    Incompatible types:
    Required: char
    Found: int


    how can I make this work?

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: changing chars by using integers in variables

    Use casting
    Code:
    newChar = ( char ) ( ( int ) 'a' + amount ) ;
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width