What im trying to do is create a file with the name "triangular_10.txt" where the number in the file name is the number the user entered. From there I want the text file to have the triangular series of numbers. So if the user enters 10, it'll display the first 10 numbers of the triangular series. So far the file name change is working.
The algorithm is here that I used for PHP:http://www.codecodex.com/wiki/Calculate_a_triangle_number
eg . user enters 10. Result in txt file is first 10 numbers in the triangular series = [1, 3, 6, 10, 15, 21, 28, 36, 45]
This is what I have so far but Im not having any luck! At the moment its only writing the number I entered on to the txt file and nothing else! Any ideas?
$number = $_POST['number-entered'];
foreach ( range(1, 1000) as $i ) {
$triangle_numbers[] = $i * ( $i + 1 ) / 2;
}
//make a file
$contents = fopen('gs://a1-task22020.appspot.com/triangular_' .$number. ".txt", "w");
fwrite($contents, $number);
//open the file
$contents = fopen('gs://a1-task22020.appspot.com/' . $contents, 'w');
// re-open the document if you put something in it
fwrite($contents, $number);
fclose($contents);
}
}