create int out of several charArray elements

  • From: Alex Hall <mehgcap@xxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Wed, 27 Feb 2008 17:58:52 -0500

Hi all
I am still working on Battleship for my class. I tell the user to type in coordinates as expected in battleship, that is, a1 or g4. I use a string to store that input, lowercase the string, then convert it to a char array and cast the first element (the letter) to an int, then subtract 97 since a actually means the first gameboard slot (0, ascii a is 97 and 97?97=0). I take the second element, the number, and cast to an int but subtract 49. The problem is that my professor wants nothing less than a 15x15 grid. If I continue converting the way I am, then a1 and a12 look the same to the program since array[1]=1 and that is all it looks for. How can I tell it that I want all elements after 0 to be strung together to form an integer, but not added? Take b15. I don't want to turn elements 1 and 2 into 6 but rather keep them as 1 and 5 but string them together as 15. Maybe there is a way to convert a string to an int? Thanks for any help.

Have a great day,
Alex
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: