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.