Arduino Projects Book: Project 07 error code

I’m getting this error:
Arduino:1.7.8 (Windows 8.1), Card:“Arduino Uno”
Keyboard_Instrument.ino:3:18: error: array must be initialized with a brace-enclosed initializer

Error during compilation.

And here’s the code:

int buttons1[6];        //set up an array with 6 integers

int buttons[0] = 2;      // give the first element of the array the value 2

int notes[] = {262,294,330,349};


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  int keyVal = analogRead(A0);
    Serial.println(keyVal);

  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);
  }

}
int buttons[0] = 2;      // give the first element of the array the value 2

You cannot do that outside a function. You have either to do it when you create the array (normal if initial value is fixed) or in the setup.

You made a real mess when you copied the code didn't you? It's no longer on line 18 and the code isn't complete. Where is the include of the tone library? Next time, post the whole code.

Ow, and btw, you're comments are really crap. A comment should clarify what something does or what something is used for. So not "give the first element of the array the value 2", but WHY do you want the first element to be 2? "set up an array with 6 integers", yes, I can see that! But what is it used for? etc

it is the whole code..... i copied it from the book..

Then I would scrap the book because it's very bad...

i’ll send some pics soon and you’ll see,and i know that the book is crap, but i most follow it because of school…

first pic:
https://mega.nz/#!gMFQ2aZS!jYCanHyRVbYZiA6bnefWlqpkCKVOGGodUQoothGcTP8

secound pic:
https://mega.nz/#!lQ91ED5K!wNWjX87mJKuJ1bShfLwqFZq-PZcq2BkrUTEadmOl05o

third pic:
https://mega.nz/#!dBUjxC4Y!Z0ELS0ZUKyPI8_2E_C7PavFh5bzbIpQ00BkP-5t2MYc

some more pics for the text beside the code:

first: https://mega.nz/#!IJVRCQZI!KXEJ9FyE0QyZ5QK_g-G-qBhbKzTB_J-yo7q28aaJmgw

secound: https://mega.nz/#!ldt2lZII!vKw1bMuX1P7LuF43GmZXYOGZjTvMrxp6PFuKqO5gmEw

third: https://mega.nz/#!AB9xkCJA!sXg0cn48fVwOK1ZzTFXRb2KCkCHIbNgR5L1UXUpn0H8

fourth: https://mega.nz/#!AV9mUaSZ!D7QNyqdEMbuJ-YATYFi61GSrhBBsQuXGur0e4MKKmWk

You could have made a nice overview picture and placed it somewhere you can view it easy... (like Google drive)

But uhm, without including tone library it's not going to work.

Btw, I don't see

int buttons1[6];        //set up an array with 6 integers

int buttons[0] = 2;      // give the first element of the array the value 2

being part of the program. No line number etc. So I think it's just a explanation about making an array with or without initialization. It makes sens because the array is never used in the program...

It is there. I think it’s the first one but not sure; picture ending with 111107.jpg

Hi, Can you post a picture of the front of the book please, one picture of the complete front cover will do. If you use REPLY rather than QUICK REPLY you will find an ATTACHMENT facility, this is easier than going to an external file carrier.

Thanks.. Tom... :)

These two lines:

int buttons1[6];        //set up an array with 6 integers

int buttons[0] = 2;      // give the first element of the array the value 2

don't reference the same variable. Further, they aren't used in the program anyway, so why are they even there? If you want the first element to equal 2, you could use:

int buttons1[6] = {2};        //set up an array with 6 integers

Also, use Ctrl-T in the source code window to reformat it with a standard C style before posting. It makes it easier for us to read.