Advertisement
moldovexc

var2_1

Dec 14th, 2022
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace var2
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.  
  23.         }
  24.  
  25.         private void button1_Click(object sender, EventArgs e)
  26.         {
  27.  
  28.             // Create a random number generator
  29.             Random rnd = new Random();
  30.  
  31.             // Loop through each day of the week
  32.             for (int i = 1; i <= 7; i++)
  33.             {
  34.                 // Add the day of the week to the list box
  35.                 listBox1.Items.Add("Day " + i);
  36.                 int sum = 0;
  37.                 int max = int.MinValue;
  38.                 int min = int.MaxValue;
  39.                 // Loop through 10 examples for the current day
  40.                 for (int j = 1; j <= 10; j++)
  41.                 {
  42.                     // Generate a random temperature between -80 and 80 degrees
  43.                     int temp = rnd.Next(-80, 81);
  44.                     sum+= temp;
  45.                     if(temp > max) max = temp;
  46.                     if (temp < min) min = temp;
  47.  
  48.                     // Add the temperature to the list box
  49.                     listBox1.Items.Add("Example " + j + ": " + temp + " degrees");
  50.                 }
  51.                 double avg = (double)sum / 10;
  52.                 listBox1.Items.Add("Average temperature: " + avg + " degrees");
  53.                 listBox1.Items.Add("Maximum temperature: " + max + " degrees");
  54.                 listBox1.Items.Add("Minimum temperature: " + min + " degrees");
  55.             }
  56.  
  57.         }
  58.  
  59.         private void richTextBox1_TextChanged(object sender, EventArgs e)
  60.         {
  61.  
  62.         }
  63.     }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement