i'm trying to combine the readwrite code with the random() code NEED HELP ASAP!!

what im trying to do is make a code that tells the arduino and the sd card shield to open or create a .txt then after the arduino opens or creates the file to then read the code Random() (that i found on the reference page) and put the results in the .txt file so then later on i could save those numbers.

this is the code i have so far:

#include <SD.h>

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 10. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println(

This is where im having trouble the program keeps saying that im missing this ; be for the { but when i add it, the program then says it cant read that part of the code

 {

      randomSeed(analogRead(0));
  // print a random number from 0 to 299
        randNumber = random(300);
        Serial.println(randNumber);  

          delay(50);
      }
)
	// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{

}

please help

p.s the pinmode is 10 because i have the seed studio sheild

First, welcome to the Forum.

As a newcomer, you should read the first two posts to this Forum, as they lay out the guidelines to be followed when posting to the Forum. The fact that you posted your entire sketch is a step in the right direction, but please use code tags from now on (i.e., the '#' button when you are posting). Also, tell us exactly what it not going correctly and what errors or error messages you are seeing.

I fixed it and pointed out what the problem is and where its at

if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println(

Incomplete line

the program keeps saying that im missing this ; be for the { but when i add it, the program then says it cant read that part of the code

When we say the exact error message, that's what we mean - not what you interpret it as.

Can you post the whole sketch as a single item. There seems to be something missing between the two existing pieces.

It would also help if you post the first 3 or 4 lines of the error message.

The compiler usually identifies an error at the first place it runs into trouble but the cause of the trouble might have been a little earlier - perhaps because the compiler didn't realize some piece had ended , may due to a missing ; or }

Read back carefully through the earlier codde looking for typos.

...R

this is the error code that shows up before i add the ;

[code]random_numbers.ino: In function 'void setup()':
random_numbers:52: error: expected primary-expression before '{' token
random_numbers:62: error: expected `;' before 'myFile'

and this is the error code after i add the ;

random_numbers.ino: In function 'void setup()': random_numbers:52: error: expected primary-expression before ';' token random_numbers:55: error: 'randNumber' was not declared in this scope random_numbers:60: error: expected primary-expression before ')' token random_numbers:60: error: expected `;' before ')' token

and these are the two codes that i wanna combine into one

this code is from the reference page called Random()

long randNumber;

void setup(){
  Serial.begin(9600);

  // if analog input pin 0 is unconnected, random analog
  // noise will cause the call to randomSeed() to generate
  // different seed numbers each time the sketch runs.
  // randomSeed() will then shuffle the random function.
  randomSeed(analogRead(0));
}

void loop() {
  // print a random number from 0 to 299
  randNumber = random(300);
  Serial.println(randNumber);  

  // print a random number from 10 to 19
  randNumber = random(10, 20);
  Serial.println(randNumber);

  delay(50);
}

and this is the code from learning page ReadWrite

#include <SD.h>

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
	// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
	// nothing happens after setup
}

and this is the code where i thought the 2 codes would or could work together

#include <SD.h>

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println(
    
   {
     randomSeed(analogRead(0));
  // print a random number from 0 to 299
        randNumber = random(300);
        Serial.println(randNumber);  

          delay(50);
    }
)
	// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
	// nothing happens after setup
}
    myFile.println(

You STILL haven't fixed this. Why the f**k not?

@PaulS beat me to it ...

...R