Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- public class Bhaskara : MonoBehaviour {
- public Text textA, textB, textC, textResults;
- public void Calculate() {
- try {
- var a = float.Parse(textA.text);
- var b = float.Parse(textB.text);
- var c = float.Parse(textC.text);
- var delta = Mathf.Pow(b, 2f) - 4f * a * c;
- var result1 = -b + Mathf.Sqrt(delta) / 2f * a;
- var result2 = -b - Mathf.Sqrt(delta) / 2f * a;
- textA.text = "x1= " + result1 + "\nx2= " + result2;
- }
- catch(DivideByZeroException) {
- textResults.text = "Cannot divide by zero";
- }
- catch {
- textResults.text = "Error";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement