# problem with loop while writing an array

Here is my code:

``````const int analogInPin1 = A0;
const int analogOutPin = 9;
int g = 0;
int m = 0;
int l = 0;
int G = 0;
int M = 0;
int L = 0;
int array[7]={'*',G ,':', M ,':', L,';' };
void setup() {

Serial.begin(115200);
}

void loop() {

G = map(g, 0, 1023, 0, 5);
analogWrite(analogOutPin, G);

// print the results to the serial monitor:
//wSerial.print("gin = " );
//w Serial.print(g);
//w Serial.print("\t gout = ");
//w  Serial.println(G);
// map it to the range of the analog out:
M = map(m, 0, 1023, 0, 5);
// change the analog out value:
analogWrite(analogOutPin, M);

// map it to the range of the analog out:
L = map(l, 0, 1023, 0, 5);
// change the analog out value:
analogWrite(analogOutPin, L);
array[1]=G;
array[3]=M;
array[5]=L;
// int array[]={G,M,L};
for (int i=0;i<7;i++)
{
Serial.print(array[i]);
Serial.print('\t');
if(i==6)
Serial.println();
// Serial.println(array[3]);
// Serial.println(array[5]);
}
// print the results to the serial monitor:
//w  Serial.print("lin = " );
//w Serial.print(l);
//w Serial.print("\t lout = ");
//w Serial.println(L);

delay(2000);
}
``````

What is this code supposed to do?

What are you trying to do?

What’s the problem you get?

Perhaps you're confusing the ASCII values of characters with their visual representations.

Who knows?

We both know. You can't mix different types like this in C/C++

``````int array[7]={'*',G ,':', M ,':', L,';' };
``````

It compiles because it's legal, but it doesn't do what you expect because when you try to print '', for example, the print function sees it as an int (which is how you declared it) with the value 42 (which is the ASCII value of '').

And now we're here, those are the most terrible variable names. Single letter names and

``````const int analogInPin1 = A0\
``````

Seriously!