By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,823 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

MC++ quadratic equation problem

P: 3
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
Dec 18 '06 #1
Share this Question
Share on Google+
6 Replies


bplacker
100+
P: 121
well, if I understand this correctly, you just say:

TextBox1.Text = num1

or whatever value you want
Dec 19 '06 #2

P: 3
Thanks for the reply. I tryed textBox1.Text = num1; but I get a error saying "error C2228: left of .Text must have class/struc/union type." I'm not sure what this means. Thanks
Dec 19 '06 #3

bplacker
100+
P: 121
well you have to have a text box that is called textBox1, in order to do textBox1.Text, maybe thats the problem? also.. if num1 is declared as something other than a string, you might need to do num1.toString()
Dec 19 '06 #4

P: 3
Yup, I do have a textbox called textBox1, spelled exectly the same, with a capital B in Box too.
Dec 19 '06 #5

bplacker
100+
P: 121
which framework are you working with?

1.1 or 2.0?
Dec 19 '06 #6

bplacker
100+
P: 121
oh... I didn't see you are using C++.

it should be textbox1->Text = num1, or something similar to this. C++ uses pointers!
Dec 19 '06 #7

Post your reply

Sign in to post your reply or Sign up for a free account.