'average' was not declared in this scope

Please see reply #2.

Which board are you compiling for, because "sum" is going to run out of steam on the eight bitters.

The compiler did not lie

average was not declared in that scope, or any other scope for that matter

As advised by the person on here that gave me the link for:
https://www.halvorsen.blog/ ?

I don't really see how that answers what I asked for.

The tutorial with the problem code: https://www.halvorsen.blog/documents/technology/resources/resources/Arduino/Programming%20with%20Arduino.pdf

That is indeed failing at some places. He should have tested the examples.
Many code and libraries for Arduino is at Github.com, then someone can make an "Issue" and tell there is something wrong.

The "scope" is compiler talk. The compiler can not find the declaration of the "average" variable.

There's a very similar topic here

That doesn't make it a blog that the Arduino forum is responsible for.

Anyway here's your code fixed at least to compile, see the <<<<< line.

int x; int sum = 0; float gjennomsnitt = 0;
float average; // <<<<<<<<<<<<< you need this
void setup()

void loop()
  sum = 0;
  for (int i = 0; i < 100; i++)

    x = random(100);
    sum = sum + x;

  average = sum / 100;
  Serial.print(" Sum = ");
  Serial.print(" , Average = ");
1 Like

Which board are you compiling for, because "sum" is going to run out of steam on the eight bitters.

There we are. That means nothing to me. Grateful as I am for your advice, it throws me into another maelstrom of despair.


edit oh wait, that's your initials

If you had posted the error message, as requested, I'd know which board you were compiling for, so your self-pity is misplaced and disingenuous

That is a marked improvement on my previous scribble. Thanks for that, but the upload is still stuck er....uploading?

Let's not drag this out into a game of twenty questions, please

Easiest way to post code is, in the ide, go control-t which does sexy indenting, then go edit > copy for forum (or control, shift, c) and then just control-v that into your post.

That is a little bit on the hostile side, may I say. I only tell it the way it is, for me, sitting her, confused....

This was a genuine request for help. If thine eye offends thee.....

@cut-me-own-throat_dibbler - remember that 90% of the people in this forum are here to help rather than be know-it-all-dicks.

I don't know anything about the tutorial thing that you are doing.. but if you explain your specific problem clearly then there is an amazing amount of knowledge here to help you solve your problem.


I think you've got your possessive pronouns somewhat muddled...

You posted a near identical topic three weeks ago.
You were asked then to provide code and messages and asked to use code tags.

Twenty three days later, the same conversation...

The author is Norwegian.
Was it really too much of a leap of intellect to type the word "gjennomsnitt" into Google Translate?
It's clearly not an English word, and equally obviously, it is a variable name, so not part of C++, and because it isn't used anywhere else in the sketch, it might just be significant.

(IMO, neither "x", "sum" nor "gjennomsnitt" merits global scope)

In German that would be "Durchschnitt", and in Spanish, "promedio". The possibilities seem endless!

Kind of embarrassing that the author did not bother to test his own examples, though.

I thought that as soon as I saw "int sum"