it's my first day messing around with C++. I'm trying to do just a really basic code looking for the roots in a quadratic equation. Here is my code so far:
#include <iostream>
#include <cmath>
int main () {
int a, b, c;
double root1, root2;
std::cout << "Enter the integers a, b, and c to fit in the quadratic equation: ax^2 + bx + c >> " << std::endl;
std::cout << "a = ";
std::cin >> a;
std::cout << "b = ";
std::cin >> b;
std::cout << "c = ";
std::cin >> c;
std::cout <<"\n";
std::cout << "Quadratic equation to solve is : " << a << "x^2 + " << b << "x + " << c <<std::endl;
root1 = (-b + sqrt(b*b - 4*a*c))/(2*a);
root2 = (-b - sqrt(b*b - 4*a*c))/(2*a);
if (root1 && root2 != nan) {
std::cout << "root 1 = " << root1 << std::endl;
std::cout << "root 2 = " << root2 << std::endl;
}
else
std::cout << "no root exists" << std::endl;
return 0;
}
I'm getting this error:
invalid operands to binary expression ('double' and 'double (*)(const char *)')
in the line:
if (root1 && root2 != nan)
I'm looking for a simple test to see if the roots exist and this obviously doesn't work. Thanks in advance for your help!