Debug error - variable not initialized

Hello!
So.. Basically what my file is trying to do is to open a .txt file, read it and then solve the quadratic equation with numbers from the .txt file. Now I realize that I'm probably doing some parts wrong, and I'm fine with that.
My problem is that every time I run the program, a debug error occurs stating that 'b' is being used without being initialized. I've defined it, so I'm not sure why the computer is having such a problem.

Here's my code so far:

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
#include<iostream>
#include<fstream>
#include<cmath> 
using namespace std;

int main ()
{


	ifstream quad;
	quad.open ("N:\CS140\Week 6\quad.txt");
	
		double a, b, c, root1, root2;

	root1 = (b + sqrt(b*b-4*a*c))/(2*a);
	root2 = (b - sqrt(b*b-4*a*c))/(2*a);
	
	
	if (quad.is_open())
	{
	cout << quad << endl;
	
	cout << "Choose a set of numbers and enter them:";
	cin >> a >> b >> c;

	}

	if (quad.fail ())//used if quad.txt doesn't open.
	{
		cerr <<"The file 'quad.txt' could not be opened."<<endl;  
	}
	


}//end main 


Any feed back would be great, thanks!
At line 13 you declared the variables,
and used them at line 15, without setting what they are.

You have to set them before manipulating them.

Try to move line 24 to line 14.
Last edited on
That got rid of the error. Thanks!
Topic archived. No new replies allowed.