trueRMS calculation for acoustic/audio signal

The below is code for true RMS calculation. I made a mistake in initializing timer and calculating number of samples. As a result, Output is not as desired. And also, did I defined the pre-scalar correctly ?.
I am new to the programming, so please excuse any basic mistakes.

Please Help … !!!

/* RMS calculation of Acoustic signal(0-20kHz)*/

// This project uses Arduino UNO R3(http://arduino.cc/en/Main/arduinoBoardUno) & Digit Shield(https://nootropicdesign.com/digitshield/) to display the output value 
// Since UNO board has timer of 8MHz, The prescalar is set to 16 to set the sampling frequency to 38.4kHz(although not twice of input frequency, initially will be testing it for accuracy)
// The input is continuosly attached to analog pin A1
// The program will be intialized based on the state of digital pin 6
// An LED attached to digital pin 7 will glow to indicate the active input signal
// Final RMS value will be displayed on seven segment display of digit shield


#include <DigitShield.h>  // Includes header file for digit shield display

const int buttonPin = 6 ; // Initialize digital pin 6 as buttonPin
int buttonState ;         // Initialize buttonState for HIGH or LOW
const int ledPin = 7;     // Initialize digital pin 7 as ledPin

int i ;                   // Initialize i for incrementing in for loop

unsigned long start_times;// Variable to store start time of the program
unsigned long stop_times; // Variable to store stop time of the program
unsigned long sampleStart;// Variable to store start time of the each sample
unsigned long sampleStop; // Variable to store stop time of the each sample



const unsigned char PS_16 = (1 << ADPS2);                                // Command to set prescalar to 16
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);                 // Command to set prescalar to 32
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);                 // Command to set prescalar to 64
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Command to set prescalar to 128

float RMS ;       // Variable to store final result
float inputRead ; // Variable to read and store input samples
float sum ;       // Variable to store and manipulate the samples
float totalTime ; // Variable to measure and store the total time of execution of program

void setup() 

{
  
      
      DigitShield.begin();         // Initiate digit shield for displaying output value
      Serial.begin(9600);          // Initialize serial monitor
      
      pinMode(buttonPin, INPUT) ;  // Define button pin as input
      pinMode(ledPin, OUTPUT);     // Define ledPin as output
      
      ADCSRA &= ~PS_128;           // remove bits set by Arduino library
      ADCSRA |= PS_16;             // set prescaler to 16 
      
      
}

void loop() 

{
 int numberofSamples = totalTime*38461 ;          // Calculate number of samples to increment the loop
 buttonState = digitalRead(buttonPin);            // Read the button state as HIGH or LOW
  
  if (buttonState == HIGH)
  
    {
      
      digitalWrite(ledPin,HIGH) ;                 // lights up LED attached to pin 7 if the state of pin 6 is HIGH to indicate active input at Analog pin A1
      
      unsigned long start_times = micros();       // Initiate timer to start counting the time of program
      
      for(i=0 ; i<=numberofSamples ; i++)
      
        {
            unsigned long sampleStart = micros(); // Initiate timer to start counting the time of sample
            inputRead = analogRead(A1);           // Initiate Analog pin A1 as input and read the voltage
            unsigned long sampleStop = micros();  // Initiate timer to stop counting the time of sample
            sum = sum + (inputRead*inputRead*(sampleStop-sampleStart)*(5.0/1023.0)); // Input value is squared and multiplied by 'dt' and convert to a voltage value
        
         }
     
      unsigned long stop_times = micros();        // Initiate timer to stop counting the time of program 
      
      unsigned long totalTime = stop_times - start_times ;
      
      RMS = sqrt(sum/totalTime);                  // Calculate the final result         
      
      
    }



Serial.println(numberofSamples);                  // Displays number of samples in serial monitor
Serial.println(totalTime);                        // Displays total time of the program in serial monitor
Serial.println(RMS);                              // Displays final result in serial monitor
Serial.println("\n");


delay(1000) ;

if(totalTime)

    {
      
      DigitShield.setValue(RMS);                 // Display the final RMS value
      DigitShield.setPrecision(2);
      
    
    }
  
}
      unsigned long totalTime = stop_times - start_times ;
      
      RMS = sqrt(sum/totalTime);                  // Calculate the final result         
      
      
    }



Serial.println(numberofSamples);                  // Displays number of samples in serial monitor
Serial.println(totalTime);

Two completely different totalTime

variables. Why?

And what's with all the useless

white space?

I know that I have defined time and number of samples incorrectly. I am not sure how to do them. That is why I need your assistance in debugging them. And concerning white spaces, I just want the reader to understand clearly.

And concerning white spaces, I just want the reader to understand clearly.

Then use appropriate amounts.

As for defining the number of samples and/or time incorrectly, I can't help you with that. What I saw is that you are using the same name for two different variables. Either there should be ONE totalTime variable, or the two variables need to have different names.