Starting Kit, project #7 - Keyboard Instrument

The code as written on the project book is as follows:

int buttons[6]; // sets up a 6 element array
int buttons[0] = 2; // assigns 2 to the first element of the array

// sets up a 4 element array and intializes it. Starts out with
// frequencies for C (262 Hz), D (294 Hz), E (330 Hz) and F (349 Hz).
// Because it is declared before setup(), it is aglobal variable array
int notes = {262, 294, 330, 349};

void setup()
{
Serial.begin(9600); // starts serial comm with computer
}

void loop()
{
int keyVal = analogRead(A0); // reads pin A0 and stores value in keyVal
Serial.println(keyVal);

// using an If Else loop to assign each a value a different tone
if(keyVal == 1023)
{
tone(8, notes[0]);
}

else
if(keyVal >= 990 && KeyVal <= 1010)
{
tone(8, notes[1]);
}

else
if(keyVal >= 505 && keyVal <=515)
{
tone(8,notes[2]);
}

else
if(keyVal >= 5 && keyVal <=10)
{
tone(8,notes[3]);
}

else
{
noTone(8); // stops playing notes when no button is pressed
}
}

As written, it gives me the following two errors:

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: “Arduino/Genuino Uno”
sketch_07A_feb18_Keyboard_Instrument:2:14: error: conflicting declaration ‘int buttons [0]’
int buttons[0] = 2; // assigns 2 to the first element of the array
C:\Users\luisc\Downloads\sketch_07A_feb18_Keyboard_Instrument\sketch_07A_feb18_Keyboard_Instrument.ino:1:5: note: previous declaration as ‘int buttons [6]’
int buttons[6]; // sets up a 6 element array

C:\Users\luisc\Downloads\sketch_07A_feb18_Keyboard_Instrument\sketch_07A_feb18_Keyboard_Instrument.ino: In function ‘void loop()’:
sketch_07A_feb18_Keyboard_Instrument:26:23: error: ‘KeyVal’ was not declared in this scope
if(keyVal >= 990 && KeyVal <= 1010)
exit status 1
conflicting declaration ‘int buttons [0]’

I´m able to clear the first error by changing the first and second lines to read:

int buttons = {2, 0, 0, 0, 0, 0}; // sets up and defines a 6 element array
// int buttons[0] = 2; // assigns 2 to the first element of the array

but I´ve been unable to clear the second error:
‘KeyVal’ was not declared in this scope
if(keyVal >= 990 && KeyVal <= 1010)

Suggestion are welcome!!!

Please look at the way the code in your post appears.
Now read read this before posting a programming question
Now post it with code tags around it to avoid any of it being interpreted as HTML commands

Fix the first error properly by substituting

buttons[0] = 2;  // assigns 2 to the first element of the array

for

int buttons[0] = 2;  // assigns 2 to the first element of the array

Fix the second error by reading

  if(keyVal >= 990 && KeyVal <= 1010)

carefully and decide whether the variable is named KeyVal or keyVal

Thank you very much UKHeliBob. Thank you for the quick response. That solves the second error but not the first. I appreciate your time and effort. The code, as in the project book is as follows:

int buttons[6]; // sets up and defines a 6 element array
int buttons[0] = 2; // assigns 2 to the first element of the array

it wont compile, it gives the following error:

conflicting declaration 'int buttons [0]',

I went around it by rewriting the first line and rem the second to:

int buttons = {2, 0, 0, 0, 0, 0}; // sets up and initializes a 6 element array
// int buttons[0] = 2; // assigns 2 to the first element of the array

I´m still curious as why it does not compile as published in the project book. Again thanks for yor time

int buttons[6];  // sets up a 6 element array
int buttons[0] = 2;  // assigns 2 to the first element of the array

This is not part of the sketch, but a broken example of using arrays.
Delete these lines.

Note: you can find the book examples under File > Examples > 10.StarterKit_BasicKit.

The code as written on the project book is as follows:

What project book? The example sketch supplied with the Arduino does NOT look like what you (mis)typed.

If the book is that bad, set it on fire.

I stand corrected, thank you @oqibidipo@

Thank you all. Case closed!!!