Hi guys. I'm beginner in programing. I must write C++ program,
but after 5 days reading in Google now I'm very confused(my hеad will explode).
The problem is:
Write a program to find the roots of quadratic equation(MFC AppWizard -> dialog based).
Requirements:
1.use windows form(at least one button and four edit boxes)
2.use class and 1-2 objects in the class
I wrote some code, but it doesn't work.
I'll be very happy, if anyone help me.

show some code please

I can give ye' some help with solving a quadratic equation in c++, but I have no help for ye' when it comes to MFC. I could even help you solve the equation symbolically as opposed to a close decimal approximation.

Hey , for finding roots of a quadratic equation , you can use the general formula..

r1 = (- b + sqrt(d)) / (2 * a) ;
r2 = (- b - sqrt(d)) / (2 * a) ;

equation : ax² + bx + c = 0
r1,r2 : roots
d=b²-4ac

Happy holidays. After first January I will post the code. :icon_mrgreen:

first case: b^2 - 4ac=0 i.e the roots are real and equal
second case: b^2-4ac>0 (roots are real and unequal)
third case: b^2-4ac<0 (roots are imaginary)

so, u can use if statements to describe these and then u can use the formulae which mridul ahooja has posted..

in the first case, (since d=0)
the formula becomes r1=r2= -b/2ac :)

You can use ahuja solutions... Thats known as the 'sreedharacharya formula' to find x..
Also.. if it makes things simpler...(which i think it will)

x² - sx + p is the general eq of a quadratic eq

whose sum of roots is s
and product of roots is p

U can easily make a program to find those numbers

Happy new year.
m_1, m_2, m_3, m_4, m_5 and m_6 - edit boxes
The code have three errors:
a = m_1; //error C2065: 'm_1' : undeclared identifier
b = m_2; //error C2065: 'm_2' : undeclared identifier
c = m_3; //error C2065: 'm_3' : undeclared identifier
I can't fix it.
And the code:

#include "stdafx.h"
#include "iostream.h"
#include "math.h"


void noRoot(double diskriminant)
{		
	
	//m_6 = "No real roots";
}


class Cdiskriminant
{
	
public:
	double a;
	double b;
	double c;
	double d;
	double x;
	double x1;
	double x2;
	double diskriminant ();
	void input()
		{
			
			a = m_1;  //error C2065: 'm_1' : undeclared identifier
			b = m_2;  //error C2065: 'm_2' : undeclared identifier
			c = m_3;  //error C2065: 'm_3' : undeclared identifier
			
		}
};

double Cdiskriminant::diskriminant ()
{
	
	return ((b*b) - (4*a*c));
}

	void noRoot(double);


void CDetreDlg::OnButton1() 
{
	Cdiskriminant d1;
	double a;
	double b;
	double c;
	double d;
	double x;
	double x1;
	double x2;
	UpdateData(true);
	d1.input ();
	d=d1.diskriminant();
	if (d==0) 
	{
		x = b/(2*a);
		m_4 = (-d1.x);
	}
	else if (d>0) 
	{
		x1 = b+sqrt(d)/(2*a);
		m_4 = -d1.x1;
		x2 = b-sqrt(d)/(2*a);
		m_5 = -d1.x2;
	}
	else
	{
		m_6 = "No real roots";
	}
	UpdateData(false);
	return;

}

You didn't declare those variables, simply put they do not exist. In order to use them you need to declare them first. It is safe to say those 3 should be the parameters of your function. Change the function inline definition accordingly, you may also want give them a type, presumably float.

The errors are fixed. To complete the requirements I must use pointers and file I/O.
I tried to attache the files of the project, but an error occurred.

#include "stdafx.h"
#include "iostream.h"
#include "math.h"


void noRoot(double diskriminant)
{		
	
	//m_6 = "No real roots";
}


class Cdiskriminant
{
	
public:
	double a;
	double b;
	double c;
	double d;
	double x;
	double x1;
	double x2;
	double diskriminant ();
	void input(double aa,double bb,double cc)
		{
			
			a = aa;
			b = bb;
			c = cc;
			
		}
};

double Cdiskriminant::diskriminant ()
{
	
	return ((b*b) - (4*a*c));
}

	void noRoot(double);


void CDetreDlg::OnButton1() 
{
	Cdiskriminant d1, *dd1;
	double a;
	double b;
	double c;
	double d;
	double x;
	double x1;
	double x2;
	UpdateData(true);
	m_4 = 0;
	m_5 = 0;
	dd1 = &d1;
	d1.input (m_1, m_2, m_3);
	d=d1.diskriminant();
	if (d==0) 
	{
		d1.x = (d1.b) / (2*d1.a);
		m_4 = (-d1.x);
	}
	else if (d>0) 
	{
		d1.x1 = d1.b + (sqrt(d)/(2*d1.a));
		m_4 = -d1.x1;
		d1.x2 = d1.b - (sqrt(d)/(2*d1.a));
		m_5 = -d1.x2;
	}
	else
	{
		m_6 = "No real roots";
	}
	UpdateData(false);
	return;

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.