cin file input integers

Oct 31, 2010 at 6:38pm
here is my code:
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
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int main()
{	
	ifstream inFile;
	double a, b, c;							
	double linroot;
	double quadroot1, quadroot2;			// resulting roots
	double discriminant;

	cout << showpoint << fixed << setprecision(2);
	cout << "COMPUTE THE REAL ROOT(S)";
	cout << "OF A QUADRATIC OR A LINEAR EQUATION\n\n";
	cin >> Filename;
	inFile.open();
	inFile >> a;
	inFile >> b;
	inFile >> c;
	while (a != -9999 && b != -9999 && c != -9999)
	{	
		discriminant =  b * b - (4 * a * c);
		if (a == 0 && b == 0)
		
			cout << "No linear or quadratic equation is formed.\n\n";			
		else if (discriminant < 0)
			cout << "Roots are not real.\n\n";
		else if (a == 0)
		{
			linroot = -1 * (c / b);
			cout << "Root is " << linroot << " .\n\n";
		}
		else 
		{
			quadroot1 = (-b + pow(discriminant, .5)) / (2 * a);
			quadroot2 = (-b - pow(discriminant, .5)) / (2 * a);
			cout << "Roots are " << quadroot1 << " and " << quadroot2 ;
		}	
	
			inFile >> a;
			inFile >> b;
			inFile >> c;
	}
	
	inFile.close ();
	cout << "Programmer: ";
	return 0;
		
	
}


It's supposed to calculate the zeros of a quadratic and linear equation. It generates error numbers 2605 and 2661. I'm still unclear about how to successfully get a file using cin. Help would be greatly appreciated. Thanks.
Oct 31, 2010 at 7:17pm
one error comes from line 18. open() needs some arguments. see http://www.cplusplus.com/reference/iostream/fstream/open/
I don't see the other one though. Which line is it form?
By the way, it would be good if you, in your future posts, would write more than the error code.
Oct 31, 2010 at 7:27pm
I have errors listed at 27 and 28. I confused about how to get the user to input a file . A lot of the file input/output material i've read has the file specified in the code. Next time I'll try to post more than error code. I just joined today because of this problem.
Oct 31, 2010 at 7:37pm
Okay I added this:
 
char Filename[20];


it's fixed. Do you always set that up? It seems odd to use the char data type.
Oct 31, 2010 at 10:47pm
Oh. well, if you need a variable, you have to declare it.
What's odd about char ? If you want you could (and probably should) use std::string though.
Oct 31, 2010 at 11:11pm
thanks for your help!
Topic archived. No new replies allowed.