How do I write this C++ sentinel-controlled while loop?
I need to write a sentinel-controlled while loop to see if the coefficients of a quadratic equation have real roots using a nested decision. A character q must be my sentinel. This is what I have so far, but it doesn't really work and I'm getting lost...
# include <iostream>
# include <iomanip>
# include <cmath>
using namespace std;
int main ()
{
//Declare Variables
double a, b, c, r1, r2, descriminant;
char q;
char SENTINEL = q;
cout << setiosflags (ios::fixed)
<< setiosflags (ios::showpoint)
<< setprecision (3);
cout << "Input the Value for a or q to Quit: " << endl;
cin >> a; // read a
while (a!= SENTINEL)
{
if (a == 0)
cout << "Zero Divide" << endl;
else if (a != 0)
cout << "Input the Value for b or q to Quit: " << endl;
cin >> b; // read b
cout << "Input the Value for c or q to Quit: " << endl;
cin >> c; // read c
if (descriminant < 0)
cout << "No Real Roots" << endl;
else if (descriminant >= 0)
cout << setw(6) << "The Real Roots Are: " << endl;
cin >> r1; //read r1
cin >> r2; //read r2
descriminant = pow(b,2) - (4 * a * c);
r1 = (-b + (pow(b,2) - (4 * a * c))) / (2 * a);
r2 = (-b - (pow(b,2) - (4 * a * c))) / (2 * a);
cout <<"Root One is: " << r1 << endl;
cout <<"Root Two is: " << r2 << endl;
}
system ("PAUSE");
return 0;
}