PDA

Click to See Complete Forum and Search --> : changing chars by using integers in variables


velociraptor
Oct 30th, 2006, 05:56 PM
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?

ComputerJy
Oct 31st, 2006, 12:19 AM
Use castingnewChar = ( char ) ( ( int ) 'a' + amount ) ;