Help with sentinel loop and nested decision

I have to write a program to solve a quadratic equation and have different outputs based on the input (zero divide, no real roots, and the answer). I'm having problems right now making the program not find roots if there is an error condition, and I'm also get a repeating output when I use 'Q' to terminate the loop. Here is what I currently have I hope someone can help point out whats wrong with what I got.



#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

char Q='\0';
const char SENTINEL='Q';

int main ()
{
float A, B, C;
float root1, root2;
float discr;
while (Q!=SENTINEL)
{

cout<<"Enter values of A, B, and C or Q to terminate the loop\n";
cin>>A>>B>>C;

if (A==0)
cout <<"Zero divide"<<endl;
else if (discr<0)
cout <<"No real roots"<<endl;
else if (discr>0)
discr=pow(B,2)-(4*A*C);
root1=(-B - sqrt(B * B - 4 * A * C)) / (2 * A);
root2=(-B + sqrt(B * B - 4 * A * C)) / (2 * A);
cout<<"The two roots are"<<root1<<"and"<<root2<<endl;
}

system ("pause");
return 0;
}

Topic archived. No new replies allowed.