Prompt the user for 3 numbers a b and c as part of the quadr
Prompt the user for 3 numbers a, b, and c as part of the quadratic equation ax^2 + bx + c = 0. Use the quadratic equation formula from the notes to determine if there are no real roots, one real root, or two real roots. Remember divide by 0.0 is undefined. You must create a function for the quadratic formula. Your function should not allow division by 0.0. and should not allow the computation of a squareroot of a negative number. You function should return true if there are any roots, and false otherwise. If there are roots your function also needs to pass those root back to the main block for output. Do not use global variables for anything. Output from your program might look like: Enter a: 2.0 Enter b: 5.0 Enter c: -3.0 There are two real roots and they are -3.0 and 0.5 Enter a: 0.0 Enter b: 5.0 Enter c: -3.0 There are no real roots Enter a: 1.0 Enter b: -3.0 Enter c: 0.0 There are two real roots and they are 3.0 and 0.0
Solution
#include<iostream>
using namespace std;
int main()
{
double a,b,c;
cout<<\"a :\";
cin>>a;
cout<<\"\ b :\";
cin>>b;
cout<<\"\ c:\";
cin>>c;
bool x=quadratic(a,b,c);
if(x)
cout<<\"\ there are real roots \"<<b<<\" and \"<<c;
else
cout<<\"\ there areno real roots\";
return 0;
}
bool quadratic(double a,double b,double c)
{
if(a==0.0)
return false;
else
{
tot=((b*b)-(4*a*c));
if(tot==0.0){
cout<<\"single root :\"<<-(tot/(2*a));
return true;
}
if(tot>0.0)
return true;
if(tot<0.0)return false;
}
}

