Create an application that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify how many random numbers the file will hold and should use a SaveFileDialog control to let the user specify the file’s name and location.

Respuesta :

Limosa

Answer:

The following code is written in C# programming language:

private void saveButton_Click(object sender, EventArgs e)

       {

               StreamWriter usersFile;

        int randomNumberAmount =int.Parse(inputTextBox.Text.ToString());;

               int randomNumber = 0;

               int count = 1;

               while (count <= randomNumberAmount)

               {

                   Random rand = new Random();

                   randomNumber = rand.Next(100) + 1;

                   count++;

               }

               if (saveFile.ShowDialog() == DialogResult.OK)

                   {

                       usersFile = File.CreateText(saveFile.FileName);

                       usersFile.WriteLine("Random Number " + count + "is: " + randomNumber + "\r\n");

                   }

                   else

                   {

                       MessageBox.Show("Operation cancelled!");

                   }

              }

Explanation:

Here, we define a class, then we create an object of the StreamWriter.

Then, we create three integer variable and initialize the value init.

Then, we set the while loop and pass the condition.

Then, we set the if condition and check the condition and create following body init.

Then, we create the else part of the if condition.

ACCESS MORE