Getting a maths componant to run

I am still having problems with a maths part of my sketch:

};                                                        UP to this point the rest runs well...

 short   calculations(){
   int val1 =analogRead(A2);      //Vin
   int val2 =analogRead(A3);     //V50
   int val3 =analogRead(A4);     //VL
   int val4 =sq(val1) - sq(val2) - sq(val3) / 2 * val2;    //gives VrL
   int val5 =sqrt(sq(val3) - sq(val4));                    //gives Vxl
   int val6 =(val3 * 50) / val2;                           //gives Rl
   int val7 =(val5 * 50) / val2;                           //gives XL
   int val8 = sqrt(sq(val6-50)+(sq (val5)) / sqrt(sq(val6 +50) + sq(val7)));       // give p
   int val9 = 1 + val8/1 - val8;   //give SWR
   lcd.setCursor(0, 3);
   lcd.print(val1);
   Serial.println(val1);
 };

I can't use void as it has to return values ( I think I can't) I have put short in for now as I am out of my depth !!!!
First time I've had to use maths, have looked around for an answer but drawn a blank.
Do I have to load a library to the sketch for maths functions ?
This is all to do with being given 3 items (val1 = Vin , on Aread(A2), val2 = V50 on Aread(A3), val3 =VL on Aread(A3).
Do I have to put anything in the start or void setup.
I have declared val1 - val9 in the start section.
It seems to not even see the section is there as nothing is printed on the LCD or serial print.
Any help please....

VF03.ino (6.62 KB)

you are not returning anything from the function.

A function declared with a return type, should return a value.

But you don't necessarily need to return a value to get an outcome from a function on arduino, you can just modify global variables inside the function, which other parts of your program can use.

I don't know what this sq( ) that you have is.

To use functions like sqrt or sin, you may need to include math.h

If you have declared global variables like val1 in your sketch, then do not declare them again in your function, as you have done. The variable in your function will be a local variable inside the function, and completely separate from the global variable with the same name.

I suggest you get a competent textbook and learn about "scope" in C/C++ rather than trying to write random garbage.

sqrt( ) is a float function. You can put it in an equation full of integers but you are not going to get sensible behaviour.

Get a competent C/C++ textbook and learn about the important differences between integer and floating point arithmetic.

your first problem seems to be that you never call the calculations() function. you need to add it to your loop() function somewhere.

You don't have to import any libraries to do simple math functions like +, -, /, *. sq and sqrt is also provided without needing a library.

If the calculations function need to give an answer, you need to specify the type of the answer as the return type of the function. If it doesn't need to give an answer, you can use void. In this case it seems like it writes the answer to the LCD and therefore probably doesn't need to return the answer to the caller, and therefore void should work.

think of it as whether you are asking a question, or just giving an instruction

//need to return an answe, so specify a type
byte howManyBeersInTheFridge() {
 return 12;
}

void consumeBeer() {
  // no need to return anything, we'll just get drunk over here.
}

You are declaring val1 to val9 in multiple scopes, and are therefore creating shadow variables. There are plenty of posts explaining this, I suggest you read them, this may not be causing any issues for you right now, but may well make you pull your hair out if you continue to develop this program further.