Hi, I'm doing a school project where I need to make a program to calulate the quadratic equation. Now, I already got that part taken care of with the following code:
#include "stdafx.h"
#include "math.h"
#include "stdlib.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
String *firstnum,
*secondnum,
*thirdnum;
double num1, num2, num3, answer, root, root2, answer1, answer2, complex, complex2, complex3;
Console::Write(S"Enter the first number: ");
firstnum = Console::ReadLine();
Console::Write(S"Enter the second number: ");
secondnum = Console::ReadLine();
Console::Write(S"Enter the third number: ");
thirdnum = Console::ReadLine();
num1 = Int32::Parse(firstnum);
num2 = Int32::Parse(secondnum);
num3 = Int32::Parse(thirdnum);
answer = num2*num2 - 4*num1*num3;
if(answer == 0)
{
root = -num2/(2*num1);
Console::WriteLine(S"\nThe answer is {0}.", root.ToString());
}
answer1 = sqrt(answer);
if(answer > 0)
{
root2 = (-num2 + answer1) / (2*num1);
Console::WriteLine(S"\nThe answer is {0}", root2.ToString());
root2 = (-num2 - answer1) / (2*num1);
Console::WriteLine(S"\nThe answer is {0}", root2.ToString());
}
answer2 = abs(answer);
complex = sqrt(answer2);
if(answer < 0)
{
complex2 = -num2 / (2*num1);
complex3 = complex / (2*num1);
Console::Write(S"\nThe answer is {0}", complex2.ToString());
Console::Write(S"+{0}", complex3.ToString());
Console::WriteLine(S"i");
Console::Write(S"\nThe answer is {0}", complex2.ToString());
Console::Write(S"-{0}", complex3.ToString());
Console::WriteLine(S"i");
}
return 0;
}
But now I need to do this same thing by creating a GUI using textboxes and buttons. Now, I would have 3 textbox where the user would input the 3 numbers(num1, num2, num3), click on a button to do the calulation, then display the answer into a 4th textbox. My problem is I'm not sure how to declare the textbox to equal to the num1, num2, and num3 that I have already used. I hope my question is understandable because I'm kinda new to this as I'm still learning. Thanks in advance