CodePudding user response:
Application wizard generates a based on the MFC dialog application, under the resource editor to add several static string and edit box, associated control and variable, the OnOK calculation and output...Which has a problem?
CodePudding user response:
entry level problem, is not function work? Or did not know how to use controls, or you want a whole procedure,CodePudding user response:
How to output in an edit box x1 x2==resultsEdit box code, please answer!
CodePudding user response:
#include
Void CDlg1Dlg: : OnBnClickedOk ()
{
//TODO: add the control notification handler code
//a * x ^ 2 + b * x + c=0;
Double a=0, b=0, c=0;
Cstrings szItem;
//value from the Edit
GetDlgItemText (IDC_EDIT_X2 szItem);
A=_tcstod (szItem, NULL);
GetDlgItemText (IDC_EDIT_X1 szItem);
B=_tcstod (szItem, NULL);
GetDlgItemText (IDC_EDIT_C szItem);
C=_tcstod (szItem, NULL);
SzItem. Empty ();
If (a==0)//a equation
{
If (b==0)
{
If (c==0)
{
Any szItem=_T (" ");
}
The else
{
SzItem. The Format (_T (" Error (% lf==0)????? "), c);
}
}
The else
{
//x=- c/b
SzItem. The Format (_T (" x=% lf "), - c/b);
}
}
The else//quadratic equation
{
//x=(a - b + SQRT (b ^ 2-4 ac))/2 a
Double ft=b * * a * b - 4 c.
If (ft<0)
{
SzItem. The Format (_T (" Error (ac) b2-4=% lf & lt; 0 "), ft);
}
Else if (ft==0)
{
Double x=(a - b)/(2 * a);
SzItem. The Format (_T (" x=% lf "), x);
}
The else
{
Double x1=(a - b + SQRT (ft))/(2 * a);
Double x2=(a - b - SQRT (ft))/(2 * a);
SzItem. The Format (_T (" x1=% lf, x2=% lf "), x1, x2);
}
}
//output
SetDlgItemText (IDC_OUT_X szItem);
}
CodePudding user response:
Positive solution upstairs!!!!!