関数に値を格納する参照変数に問題があります。このコードのどこが間違っているのでしょうか?
//Loads temperature from a disk file and outputs them to the screen
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include "myHeader.h"
using namespace std;
//Function prototypes
void minMax (int mean[], int size, int &, int &);
//Declare Global variables
string userFile; //variable for user input of file
string date; //variable for inputFile date
int low; //variable for inputFile low
int high; //variable for inputFile high
double sumLow = 0.0; //variable to hold sum of low temps
double sumHigh = 0.0; //variable to hold sum of high temps
ifstream inputFile;
const int ARRAY_SIZE = 31;
int lowTemp[ARRAY_SIZE];
int highTemp[ARRAY_SIZE];
//Accumulators
int min = 200;
int max = 0;
int count = 0;
int minTemp = 0;
int maxTemp = 0;
int main()
{
//Call the heading function
heading(8, 'A');
//Prompt user to enter a file
cout << "What file do you want to open for input? ";
cin >> userFile;
cout << endl;
inputFile.open(userFile);
minMax(lowTemp, ARRAY_SIZE, minTemp, maxTemp);
//Close the file
inputFile.close();
return 0;
}
//******************************************
//Definition of function minMax
//******************************************
void minMax (int mean[], int size, int & min, int & max)
{
for (int i = 0; (i < ARRAY_SIZE) && (inputFile >> date >> low >> high); i++)
{
lowTemp[i] = low;
highTemp[i] = high;
count = i;
sumLow += lowTemp[i];
sumHigh += highTemp[i];
if (lowTemp[i] < min)
{
min = lowTemp[i];
}
if (highTemp[i] > max)
{
max = highTemp[i];
}
minTemp = min;
maxTemp = max;
}
cout << "array size " << count + 1 << " array low " << minTemp << " array high " << maxTemp << endl << endl;
cout << endl << count + 1 << " " << sumLow << " " << sumHigh << endl;
}
プログラムがコンパイルされ、どのファイルを開くかをユーザーに尋ねます。ファイルを入力すると、戻ります。
配列サイズ 31 配列下位 0 配列上位 91
31 1831 2602
配列 High は正しいです。ただし、ファイルによると、配列の下限は 34 である必要があります。