Error opening a file on SD card

Extremely new to arduino and tried making a small program to calculate altitude, temperature, and pressure. However, every time I test it with the serial monitor, it says “error opening a.txt.”

Here’s the code

#include <Wire.h>
#include <SFE_BMP180.h>                                        
#include <SPI.h>
#include <SD.h>
const int chipSelect = 10;
SFE_BMP180 bmp180;
double Po;

void setup() {
  Serial.begin(9600);
  bool success = bmp180.begin();
  SD.begin(); 
  if (success) {
    Serial.println("BMP180 init success");
  }
   char status;
  double T, P, alt;
   success = false;
 
  status = bmp180.startTemperature();

  if (status != 0) {
    delay(1000);
    status = bmp180.getTemperature(T);

    if (status != 0) {
      status = bmp180.startPressure(3);
 
      if (status != 0) {
        delay(status);
        status = bmp180.getPressure(P, T);
       Po = P; 
}
    }}
  }
 
void loop() {
  char status;
  double T, P, alt, t;
  bool success = false;
 t = millis();
  status = bmp180.startTemperature();

  if (status != 0) {
    delay(1000);
    status = bmp180.getTemperature(T);

    if (status != 0) {
      status = bmp180.startPressure(3);
 
      if (status != 0) {
        delay(status);
        status = bmp180.getPressure(P, T);
       
        if (status != 0) {
          alt = bmp180.altitude(P, Po);
          
        
        }
      }
    }
  }
File dataFile = SD.open("a.txt", FILE_WRITE);  
  // if the file is available, write to it:
  if (dataFile){
    dataFile.print("Pressure: ");
          dataFile.print(P);
         dataFile.println(" mb");
          dataFile.print("Temperature: ");
         dataFile.print(T);
         dataFile.println(" C");
          dataFile.print("Altitude: ");
         dataFile.print(alt);
         dataFile.println(" Meters");
         dataFile.print("Time: ");
         dataFile.print(t);
         dataFile.print(" milliseconds");
          
    dataFile.close();
    // print to the serial port too:
         Serial.print("Pressure: ");
          Serial.print(P);
          Serial.println(" mb");
          Serial.print("Temperature: ");
          Serial.print(T);
          Serial.println(" C");
          Serial.print("Altitude: ");
          Serial.print(alt);
          Serial.println(" Meters");
          Serial.print("Time: ");
         Serial.print(t);
         Serial.print(" milliseconds");
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println(" error opening a.txt");
  }
}

Board is arduino nano, processor is 328P, programmer is AVRISP mkll, and there’s only one port. Any help would be appreciated

baby steps

write very simple program to open existing file on SD card

No CS pin specified at SD.begin()? Not sure if it defaults to pin 10; but otherwise sounds like a hardware problem.

Try the CardInfo example and tell us what's the output (on the serial monitor of course).