473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MC++ quadratic equation problem

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
6 1703
bplacker
121 100+
well, if I understand this correctly, you just say:

TextBox1.Text = num1

or whatever value you want
Dec 19 '06 #2
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
121 100+
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
Yup, I do have a textbox called textBox1, spelled exectly the same, with a capital B in Box too.
Dec 19 '06 #5
bplacker
121 100+
which framework are you working with?

1.1 or 2.0?
Dec 19 '06 #6
bplacker
121 100+
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

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

Similar topics

3
by: parisgoblet | last post by:
hi, i'm a freshman with c++,i got a question from my assignment,does someone could give me some ideas for that. Given the following prototype of a function that solves the roots of a quadratic...
1
by: tedla | last post by:
i want a fragment of code that accepts the coefficient of quadratic equation from user and calculate the eqt'n.
6
by: Trev17 | last post by:
Hello, I am new to C++ and i have tried for several hours to make a program my teacher has given me as a lab. Here is the Lab question: the roots of the quadratic equation ax^2 + bx + c = 0, a...
2
by: DaRok28 | last post by:
// Program Description: // This program solves quadratic equations to find their roots. This // program takes values of a, b, and c as input and outputs the root(s). // The user can repeat the...
4
by: nbkreddy | last post by:
write a program to find the roots of the quadratic equation using switch statement
2
by: ioannoual | last post by:
Hi...I 'am new in C and I want a program that solves a quadratic equation!! I try something by my self to write some code about that but I want you to help me writing a new one that will work!! ...
1
by: bbench123 | last post by:
Make a program that will ask for values of a quadratic equation (ax2+bx+c). the program must determine the roots of the equation using the quadratic equation determinants to distinguish if the roots...
1
by: candacefaye1 | last post by:
1. write a C++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message “zero divide” when A is zero, write the message “no real...
3
by: ginevralupin | last post by:
hi i m a student nd need to write a program to input coefficients of a quadratic equation and output its roots . There is some problem in this , i tried several variations but it is not working....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.