help - displaying peak altitude from a sensor

I am making an altimeter for a rocket using an arduino board, lcd display and pressure sensor.
So far, I've been able to get it working and showing the current altitude, but I'm also trying to make the altimeter show a maximum or peak value ever recorded by the sensor. I have no experience in coding.
The sensor I'm using is the BMP180

here is part of my code

void loop()
{
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  float tc = temperature*0.1;

  float Pa =  pressure*.01; //mb
  //float AS = 29.72; //current METAR reading
//http://wahiduddin.net/calc/density_altitude.htm
  float pressInHG = pressure/3386.389; //convert pa to inHG
 // pressInHG = ((int)(pressInHG*100))/100.0; //round to two dec places so we don't get constant flux
  pressInHG = ((int)(pressInHG*1000))/1000.0; //round to four dec places so we don't get constant flux


 
  float ras = 0;
  int asDownPin = 2;
  int asUpPin = 1;

  int downas = analogRead(asDownPin);
  int upas = analogRead(asUpPin);
    //Serial.println(downas);
  if(downas > 1000){
    //Serial.println("down press");
   AS = AS - .01; 
  }
  if(upas > 1000){
   // Serial.println("up Press");
   AS = AS + .01; 
  }
 

  int altitude = (int)((pow(AS,0.1903) - pow(pressInHG,(1/5.255)))/(1.212*(pow(10,-5)))*0.3048+79); //calculate altitude
  
  lcd.clear(); 

  //set the curser at the first character of the first line (char,line)
  lcd.setCursor(0,0);           
  lcd.print("H=");
  lcd.print(altitude);
  lcd.print("m.");
  
  
  lcd.setCursor(0,2);          
  lcd.print("AS: ");
  lcd.print(AS);
  lcd.print(" inHG"); 

  
  lcd.setCursor(0,3);           
  lcd.print("T=");
  lcd.print(tc);
  lcd.print(" C");

  int altitudemax = 0;
  
  lcd.setCursor(0,1);           
  lcd.print("max=");
  
  //Shows maximum altitude reached
  if (altitude > altitudemax){
    altitudemax = altitude;
  } 
  lcd.print(altitudemax);
  lcd.print("m");

  
  delay(500);
}

I'm trying to make altitudemax the peak value using the if statement, but the result sometimes decreases, I can't seem to hold the value to make the maximum altitude. Is it possible to make an increasing only value which is kept even when the altitude falls?
Is there something I can do to solve this?

Since altitudemax is created inside the loop function it is local to loop. That means it is destroyed and recreated at 0 every time the loop function exits and starts again. Put the word static in front of that line to make it persist between calls to loop.

Google "c++ scope" for a more in depth explanation.

Thanks for the reply, I'm slowly getting it now

The altimeter is working just as desired after editing the code.
I added "static" before int altitudemax

This is what the code looks like now:

void loop()
{
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  float tc = temperature*0.1;

  float Pa =  pressure*.01; //mb
  //float AS = 29.72; //current METAR reading
//http://wahiduddin.net/calc/density_altitude.htm
  float pressInHG = pressure/3386.389; //convert pa to inHG
 // pressInHG = ((int)(pressInHG*100))/100.0; //round to two dec places so we don't get constant flux
  pressInHG = ((int)(pressInHG*1000))/1000.0; //round to four dec places so we don't get constant flux


 
  float ras = 0;
  int asDownPin = 2;
  int asUpPin = 1;

  int downas = analogRead(asDownPin);
  int upas = analogRead(asUpPin);
    //Serial.println(downas);
  if(downas > 1000){
    //Serial.println("down press");
   AS = AS - .01; 
  }
  if(upas > 1000){
   // Serial.println("up Press");
   AS = AS + .01; 
  }
 

  int altitude = (int)((pow(AS,0.1903) - pow(pressInHG,(1/5.255)))/(1.212*(pow(10,-5)))*0.3048+59); //calculate altitude
  
  lcd.clear(); 

  //set the curser at the first character of the first line (char,line)
  lcd.setCursor(0,0);           
  lcd.print("H=");
  lcd.print(altitude);
  lcd.print("m.");
  
  
  lcd.setCursor(0,2);          
  lcd.print("AS: ");
  lcd.print(AS);
  lcd.print(" inHG"); 

  
  lcd.setCursor(0,3);           
  lcd.print("T=");
  lcd.print(tc);
  lcd.print(" C");

  static int altitudemax = 0;
  
  lcd.setCursor(0,1);           
  lcd.print("max=");
  
  //Shows maximum altitude reached
  if (altitude > altitudemax){
    altitudemax = altitude;
  } 
  lcd.print(altitudemax);
  lcd.print("m");

  
  delay(500);
}

A small change in code can make a big difference!