Question

So the problem is that I'm getting error C3867 when I'm attempting to close the file stream (at least that's what I hope I'm doing). The intent is to make a program that uses an input file to read in the values into an array and from there determine what the highest and lowest numbers of the array are. The arraySize can be less or more than 10 data items, and we must check the file for open errors before reading data from the file and to close the file after finished reading the elements into the array. This I can do later but it's an instruction anyway.

#include <stdafx.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
    const int arraySize = 10;
    float numbers[arraySize];
    int count = 0;
    string fileName;
    float high, low;

    fstream inputFile(fileName, ios::in);

    cout << "What is the filename you wish to use? ";
    cin >> fileName;

    inputFile.open(fileName);
    while (count < arraySize && inputFile >> numbers[count])
        count++;
    inputFile.close;

    high = numbers[0];
    low = numbers[0];

    for (int i = 0; i < arraySize; i++){
        if (numbers[i] > high)
            high = numbers[i];
        if (numbers[i] < low)
            low = numbers[i];
    }

    cout << "The highest number in the file is: " << high;
    cout << "The lowest number in the file is: " << low;

    return 0;
}

Am I missing anything?

Was it helpful?

Solution

You need to call inputFile.close() as a function with the parentheses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top