Что нового

[Математика] решение уравнения

andreitrane

Новичок
Сообщения
141
Репутация
3
почему не хочет решать квадратные уравнения?
например ввожу этот
2Х^2+5Х-25
ответ на него Х1=-5 и Х=2,5
но программа отвечает что нет решения
что надо исправить?
Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=D:\Рабочий стол\БОТ!!!\формы ботов\квадратное уравнение.kxf
$kvur = GUICreate("Квадратное уравнение", 302, 65, 362, 336)
$ainput = GUICtrlCreateInput("", 8, 8, 57, 21)
$Label1 = GUICtrlCreateLabel("Х", 64, 8, 16, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$Label2 = GUICtrlCreateLabel("2", 80, 0, 11, 17)
GUICtrlSetFont(-1, 2, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$binput = GUICtrlCreateInput("", 88, 8, 49, 21)
$Label3 = GUICtrlCreateLabel("Х", 136, 8, 16, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$cinput = GUICtrlCreateInput("", 152, 8, 57, 21)
$Label4 = GUICtrlCreateLabel("=", 208, 8, 16, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$otvet = GUICtrlCreateInput("", 224, 8, 65, 21)
$startpr = GUICtrlCreateButton("Вычислить", 8, 40, 89, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $startpr
			$a = GUICtrlRead($ainput)
			$b = GUICtrlRead($binput)
			$c = GUICtrlRead($cinput)
			$d = $b*$b+4*$a*$c
			if Number($d) < Number(0) Then
				MsgBox(0, "", "нет решений")
			ElseIf Number($d) = Number(0) Then
				$x = (-$b)/2*$a
				GUICtrlSetData($otvet, $x)
			Else
				$x1 = ((-$b)-Sqrt($d))/2*$a
				$x2 = ((-$b)+Sqrt($d))/2*$a
				GUICtrlSetData($otvet, $x1 &"; "& $x2)
				EndIf


	EndSwitch
WEnd
 

Belfigor

Модератор
Локальный модератор
Сообщения
3,608
Репутация
941
Попробуй так:
Код:
$a = Number(GUICtrlRead($ainput))
$b = Number(GUICtrlRead($binput))
$c = Number(GUICtrlRead($cinput))
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
нет, не решает
drddrd.png
 

kaster

Мой Аватар, он лучший самый
Команда форума
Глобальный модератор
Сообщения
4,020
Репутация
626
andreitrane
1. D = b^2 - 4ac а не b^2 + 4ac
2. решает. только что проверял
горе математик :smile:
 

zlo-kazan

Скриптер
Сообщения
374
Репутация
100
И ещё в догонку


Код:
$x1 = ((-$b)-Sqrt($d))/(2*$a)
                $x2 = ((-$b)+Sqrt($d))/(2*$a)


Без скобок он сначала делит на 2... а потом что осталось умножает на $a
 
Верх