Quadratic solver

I have this program that gives me a debug error saying that bFail is being ran without being initialized. I ignore it and when I enter 0 as a value of a the program still keeps on running. How can I get it to stop running.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 #include <iostream> 
#include <cmath> 
#include <string> 
#include <iomanip>
using namespace std; 

int main() 
{
	string Name;
	double a;
	double b; 
	double c; 
	double discriminant;
	double x1; 
	double x2;
	cout << scientific; 
	bool bFail; 

cout << "\t\t\t===============================\n";
cout << "\t\t\t\tQuadratic Equation\n";
cout << "\t\t\t===============================\n";
cout << "Full Name:";
getline(cin,Name); 
cout << "\n\n"; 
cout << setw(25) << Name << "\n"; 
cout << "This program will provide solutions for an equation of the form:\n"; 
cout << "\t\ta*x^2 + b*x + c = 0\n"; 
cout << "Where a,b, and c are integers and a is not equal to zero\n"; 

do{ 
	cout << "Enter value of a:"; 
	cin >> a; 

	if (a == 0)
	{cout << "No solution!\n"; 
	
	}
	
	else if (a != 0)
	{
	bFail = cin.fail(); 
	cin.clear(); 
	cin.ignore(numeric_limits<streamsize>::max(),'\n');
	}

}while(bFail == true);

do{
	cout << "Enter value of b:"; 
	cin >> b; 

	bFail = cin.fail(); 
	
	cin.clear(); 
	cin.ignore(numeric_limits<streamsize>::max(),'\n');

}while(bFail == true);

do{
	cout << "Enter value of c:"; 
	cin >> c; 
		bFail = cin.fail(); 
	
	cin.clear(); 
	cin.ignore(numeric_limits<streamsize>::max(),'\n');

}while(bFail == true);

discriminant = pow(b,2) - 4 * a * c; 

return 0; 
}
closed account (Dy7SLyTq)
set bfail to true when you declare it
Topic archived. No new replies allowed.