hey guys..I'm new here,and I need some help in this program I'm making..
Code:
//Program to show the nature of roots,solve,etcetc
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
#include <cmath>
#include <conio.h>
using namespace std;
void setcolor(unsigned short color)
{
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hcon,color);
}
int main()
{
float a,x,b,c,alpha,beta,D;
int y;
alpha = (-b - sqrt(pow(b,2) - 4*a*c))/2*a ;
beta = (-b + sqrt(pow(b,2) - 4*a*c))/2*a ;
D = pow(b,2) - 4*a*c;
cout << "\nWelcome to the Equation Solver!\n";
cout << "\nChoose one of the following -:\n";
cout << "\n1. Find a quadratic equation's nature of roots\n";
cout << "\n2. Find a quadratic equation's roots\n";
cout << "\n3. Establish the Viète relation of the roots and coefficients\n";
cout << "\n4. Quit,noobs >_>\n";
cin >> y;
switch(y)
{
case 1:
cout << "Enter coefficient 'a' - ";
cin >> a;
cout << "\n";
cout << "Enter coefficient 'b' - ";
cin >> b;
cout << "\n";
cout << "Enter constant 'c' - ";
cin >> c;
cout << "\n";
cout << "The equation is..\n";
cout << a << "x^2 +" << b << "x +" << c << endl;
cout << "\n";
setcolor(8);
if (D = 0)
{
cout << "The roots of this equation are real and equal!";
}
if (D > 0)
{
cout << "The roots of this equation are real and unequal!";
}
if (D < 0)
{
cout << "There are no roots to this equation..";
}
setcolor(7);
system("PAUSE");
break;
case 2:
cout << "Enter coefficient 'a' - ";
cin >> a;
cout << "\n";
cout << "Enter coefficient 'b' - ";
cin >> b;
cout << "\n";
cout << "Enter constant 'c' - ";
cin >> c;
cout << "\n";
cout << "The equation is..";
cout << a << "x^2 +" << b << "x +" << c << endl;
cout << "\n";
cout << "And the solutions are as follows -:\n";
setcolor(14);
cout << "x = " << alpha << endl;
cout << "x = " << beta << endl;
setcolor(7);
system("PAUSE");
break;
case 3:
cout << "Enter coefficient 'a' - ";
cin >> a;
cout << "\n";
cout << "Enter coefficient 'b' - ";
cin >> b;
cout << "\n";
cout << "Enter constant 'c' - ";
cin >> c;
cout << "\n";
cout << "The equation is..";
cout << a << "x^2 +" << b << "x +" << c << endl;
cout << "\n";
setcolor(8);
cout << "The sum of the roots is " << alpha + beta << endl;
cout << "The value of -b/a is " << -b/a << endl;
cout << "The product of the roots is " << alpha * beta << endl;
cout << "The value of c/a is " << c/a << endl;
setcolor(7);
system("PAUSE");
break;
case 4: break;
default: "Enter a number in the list\n";break;
}
return 0;
}
Can't understand..there are no syntax errors,however there are logical ones.
In case 1, the Discriminant outputs(The ones with D) don't come.
In case 2, the equations always solve to some retarded value(lol?)
Case 3 doesn't work at all...