[Solved] “variable” was not declared on this scope [C]


You have’t declared variables media, max, min. They either need to be local in main, or global. In general it is a good idea to have them as local in main, including p which you have put as global but then pass as parameter.

In your program, media, max, and min are parameters in calc. As they are, those variables can only be used inside calc.

Do I need to scan inside the main and then use the function?

If you mean scanf() to read the values from keyboard input, probably yes. It really depends on what you need.

However, while you surely need to declare the variables first, you are also overwriting the value of the parameters inside calc, ignoring whatever values are passed to the function.

float calc(DATA *p,float media, float max, float min)
{
    int a;
    max=0;
    min=20;

solved “variable” was not declared on this scope [C]