Ok jestem głąbem i nie potrafię tego zrobić. Pomógłby ktoś uporządkować to?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _4_bój
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double c, b;
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
b = Double.Parse(textBox3.Text);
/*
double closest = a.Aggregate((x, y) => Math.Abs(x - b) > Math.Abs(y - b) ? x : y);
double index = Array.IndexOf(a, closest);
textBox4.Text = Convert.ToString(closest);
int wtf=Array.BinarySearch(a, b);
textBox4.Text = Convert.ToString(closest);
foreach (double number in a)
{
if ((b -= number) <= 0)
textBox4.Text = Convert.ToString(number);
else
textBox4.Text = Convert.ToString(-1);
}
*/
public double ReturnClosestNumberPosition(double number)
{
double[] a = new double[201]
{
14.00, 11.60, 11.45, 11.30, 11.20, 11.15, 11.10, 11.05, 11.00, 10.95, 10.90, 10.85, 10.80, 10.75, 10.70,
10.65, 10.60, 10.55, 10.50, 10.45, 10.40, 10.35, 10.30, 10.25, 10.20, 10.15, 10.10, 10.05, 10.00, 9.95,
9.90, 9.85, 9.80, 9.75, 9.70, 9.66, 9.62, 9.58, 9.54, 9.50, 9.46, 9.43, 9.40, 9.36, 9.32, 9.29, 9.26,
9.23, 9.20, 9.17, 9.14, 9.11, 9.08, 9.05, 9.02, 8.99, 8.96, 8.93, 8.90, 8.87, 8.84, 8.81, 8.78, 8.75,
8.72, 8.69, 8.66, 8.63, 8.60, 8.57, 8.54, 8.52, 8.49, 8.46, 8.44, 8.42, 8.40, 8.38, 8.36, 8.34, 8.31,
8.28, 8.25, 8.22, 8.19, 8.16, 8.13, 8.10, 8.07, 8.04, 8.02, 8.00, 7.98, 7.96, 7.94, 7.92, 7.90, 7.88,
7.87, 7.86, 7.85, 7.84, 7.83, 7.82, 7.81, 7.80, 7.79, 7.78, 7.77, 7.76, 7.75, 7.74, 7.73, 7.72, 7.71,
7.70, 7.69, 7.68, 7.67, 7.66, 7.65, 7.64, 7.63, 7.62, 7.61, 7.60, 7.59, 7.58, 7.57, 7.56, 7.55, 7.54,
7.53, 7.52, 7.51, 7.50, 7.49, 7.48, 7.47, 7.46, 7.45, 7.44, 7.43, 7.42, 7.41, 7.40, 7.39, 7.38, 7.37,
7.36, 7.35, 7.34, 7.33, 7.32, 7.31, 7.30, 7.29, 7.28, 7.27, 7.26, 7.25, 7.24, 7.23, 7.22, 7.21, 7.203,
7.20, 7.19, 7.18, 7.17, 7.16, 7.151, 7.15, 7.14, 7.13, 7.12, 7.11, 7.10, 7.091, 7.09, 7.08, 7.07, 7.06,
7.05, 7.04, 7.031, 7.03, 7.02, 7.01, 7.00, 6.991, 6.99, 6.98, 6.97, 6.96, 6.951, 6.95, 6.94, 6.93, 6.92, 6.91
};
//zakladam ze tablica tuta jest wypelniona i dostepna. Nazywa sie records
int position = 0;
double closestDifference = double.Max; // z tego mozesz zrobic tuple albo dictionary
for (int index = 0; index < a.length; index++}
{
double difference = Math.Abs(a[index] - number);
if (closestdifference > difference)
{
closestdifference = difference;
position = index;
}
}
return position;
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
}
}
@up ok działa dziękuje wam bardzo i przepraszam za spam