So I read what you said about casting the character and i realized i was already doing that and that means that the program should be working, bu it wasn't, so i added some debugging println()'s. I realized that there was no loop to initialize the number that was being written to the third char!
so after working the numbercount initilization into the second loop i started trying to decipher what number i would have to add to the value to get the number versions of the characters.The number i came up with was 48. Here is the working code, thank you guys for your fast responses and great feedback.
Heres the working code:
- char[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- char[] letters = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
- char[] lettersV = {0, 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};
- char[] test = {'B', 'S', '6'};
- char[] output;
- int outputf; //first output
- int outputs; // second output
- int outputt; // third output
- void setup() {
- //println(test);
- println(" = "+convertID(test));// testing the main function.
- println(convertID(456.0));
- }
- char[] convertID(float id) {
- char output1 = 0;
- char output2 = 0;
- char output3 = 0;
- String output3str = "0";
- char[] output = {0,0,0};
- int idcopy = int(id);
-
- if(idcopy < 7010) {
-
- ////////////////////////////////////////////Majors/main below here
- int maincount = int(id) / 270 ;
- float mainremainder = id % float(270);
- int subtractmajor = maincount * 270;
- id = int(id) - subtractmajor;
- ////////////////////////////////Minors below here
- int minorcount = int(id) /10;
- float minorremainder = id % float(10);
- int subtractminor = minorcount * 10;
- id = int(id) - subtractminor;
- //////////////////////////////Numbers Below here
- int numbercount = int(id) / 1;
- int subtractnumber = numbercount * 1;
- id = int(id) - subtractnumber;
- output1 = '0';
- output2 = '0';
- for(int i = 0;i < letters.length;i++) {
- if (i == maincount) {
- output1 = letters[i];
-
- }
- }
- for(int f = 0;f < letters.length;f++) {
- if (f == minorcount) {
- output2 = letters[f];
- id = id - minorcount;
- output3 = char(numbercount + 48);
- }
- }
-
- }
- else {
- println("Input is over the maximum value");
- }
- output[0] = output1;
- output[1] = output2;
- output[2] = output3;
- if(idcopy < 7010) {
- return output;
- }
- else {
- output[0] = ' ';
- output[1] = ' ';
- output[2] = ' ';
- return output;
- }
- }
- int convertID(char[] chid) {
- int outputf = 0;
- int outputs = 0;
- int outputt = 0;
- for (int i = 0; i < letters.length; i++) // first loop checks what character the first space is and starts filling the integer.
- if (chid[0] == letters[i])
- outputf = lettersV[i]*270;
-
- for (int h = 0; h < letters.length; h++) // second loop checks the second character and applys it to the int.
- if (chid[1] == letters[h])
- outputs = lettersV[h]*10;
-
- outputt = Character.getNumericValue(chid[2]);
-
- return outputf + outputs + outputt; //returns the sum of all three spaces.
- }
Now to start cleaning it up!