expected initializer before "-" token error message

Very first sketch! Having issues implementing variable.
Error code reads “expected initializer before “-” token”
This is my sketch; also included attachment.
For future sketch inquiries should I only include file attachment or both
Thanks so much!

// this is where you define variables, librarys, ect.
int math - 0;

/* forward slash star is where you write story, take notes,
and acknowledge source then close star forward slash
*/
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);

}

void loop() {
// put your main code here, to run repeatedly:
Serial.print (“HELLO here is some M@TH!”);
Serial.print (Math);
delay (7000);

}

first_sketch.ino (423 Bytes)

int math - 0; maybe you mean int math = 0;

OK, So I replace - with = then verified. expected unqualified -ID before "-" token exit status 1 was the error code it gave me. hmm must be making a simple mistake somewhere. Thanks very much for your input!

cspaulding95:
hmm must be making a simple mistake somewhere.

Yeah, "math" and "Math" are not the same.

OK capitalized word Math.
int Math - 0;
Error code reads "expected initializer before "-" token" .
Still no dice
Thanks for the reply!

Well yo need to respect the case and use = not - to declare the initial value of your Math variable (convention is to not capitalize first letter in your variable name)

Also read post at top of the forum to know how to properly use the forum and post code

Please learn how to use code tags when posting code.

type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

So it looks like

// this is where you define variables, librarys, ect.
int math - 0;

/* forward slash star is where you write story, take notes,
 and acknowledge source then close star forward slash
 */
void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
   
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.print ("HELLO here is some M@TH!");
Serial.print (Math);
delay (7000);

}

You will also need to learn to indent properly in the IDE; it makes is far easier to read and to spot errors with e.g. {} and (). The IDE has tools → auto format to do this for you.

Now it looks like

// this is where you define variables, librarys, ect.
int math - 0;

/* forward slash star is where you write story, take notes,
  and acknowledge source then close star forward slash
*/
void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print ("HELLO here is some M@TH!");
  Serial.print (Math);
  delay (7000);

}

Note the difference that it made to the loop() function.

Now assume that you forgot a closing ) at the end of the Serial.println. After an auto format, it will clearly show

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print ("HELLO here is some M@TH!");
  Serial.print (Math;                  <------ I forgot the closing )
                delay (7000);          <------ this indentation after auto format shows clearly that something is wrong

}

We got it!
int Math = 0;
Thanks so much guys
aspiring to be better !
do I delete this post now or leave it up?

You can't delete a thread: the opening post doesn't give a delete option.

But you can edit the opening post and put something like [solved] or [answered] in the title. (Has to be opening post, not a follow up).

I would like to use "code tag" in future post.
Could someone explain how to do so?

Just hit the </> icon top left in the edit screen and type between the tags

Or, you can just type the [code]& [/code] tags in front and back of the sketch.

Re-read the beginning of reply #6 :wink:

And never delete threads once they are answered. Others might encounter the same problem and can find the answer in this thread.