'average' was not declared in this scope

I am using https://www.halvorsen.blog/, as advised.
Sketch_28a professes to be an instructable yet along with other sketches in this tutorial, it is not functioning as it should do, apparently. Even after me attempting to duplicate the code, from which I learn nothing, pixel by pixel for another failure. I have got really fed up with going through these examples that invariably come back with errors. There is one that reads
"pinMode(11, OUTPUT);"
I know that unless I change the layout of the board by adding an LED or changing 11 to 13, it will do nothing when uploaded.
I have thought that this is intentional so that I will endeavour to correct the faults and learn in the process. Alas, I have learned virtually nothing from these tutorials, replacing bad code for good code when I can is just
"parrot fashion"
to me. All this depends on where I go to get some help. This is all very disappointing, but nevertheless:
'average' was not declared in this scope. ...?
what does that mean? Why is it referred to as a scope?
Why does this tutorial, and others, talk, from the getgo about elements in the code as though I had been coached about pieces like
"int, Serial.begin(9600) etc. "
previous to me starting the tuts?
Why 9600? and how about
"float gjennomsnitt = 0"?
At no point does it state that I should know this and that before I start?
Please can someone help me out here? I have all this kit here but as usual in these forums, newbies are just skirted past for the most part?

PS Old "Scopes" that I have got working from this man's blog, now stick on uploading? More to worry about.

Post your code.
Post your error messages.
Use code tags.

Why indeed?

A bit like Abba, it was very popular in the 1970s, and is making a comeback.

By whom?

If you have an issue with the Halvorsen blog / tuts, perhaps take it up with them?

Of course, you could also post the code from the mysterious sketch28 and ask someone here to look at it.

2 Likes

OK
The Code....
int x; int sum = 0; float gjennomsnitt = 0;
void setup()
{
Serial.begin(9600);
}

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(sum);
  Serial.print(" , Average = ");
  Serial.println(average);
  delay(1000);

}

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()
{
  Serial.begin(9600);
}

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(sum);
  Serial.print(" , Average = ");
  Serial.println(average);
  delay(1000);
}
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.
CMOTD

???

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.

chill.