Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
|
ifstream fin("data.text");
int n = 5;
double x = 1.5;
char c = 'R';
string fname;
cout << "Enter file name: ";
cin >> fname;
ifstream fin(fname);
int sum = 0, next;
while( fin >> next ) {
sum = sum + next;
}
cout << sum << endl;
If the file named by the user consisted solely of the line
13,4,15what would the above program (once fixed!) output ?
Brown 71.8 Green 93.8 Jones 82.4 Smith 86.2 Worth 91.2Your program should work for any file in the same format, though you may hard-code the filename, rather than read it in from the user if you prefer.