Help with 2D array
I cant seem to put my data into a 2 dimensional array, please tell me where my mistake is
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 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
void readData();
void calculateStats(double, int);
void saveResults();
int value = 0;
int number=0;
double sum = 0, average = 0;
const filename;
int main()
{
readData();
const int ARRAY_SIZE = 5;
int numbers[ARRAY_SIZE];
int count = 0;
ifstream inputFile;
inputFile.open(filename.c_str);
while (count << ARRAY_SIZE && inputFile >> numbers[count])
count++;
inputFile.close();
cout << "the numbers are: ";
for (count = 0; count < ARRAY_SIZE; count++)
cout << numbers[count] << " ";
count << endl;
return 0;
}
void readData()
{
ifstream inputFile;
string filename;
cout << "Please enter filename." << endl;
cin >> filename;
inputFile.open(filename.c_str());
while (inputFile >> value)
{
cout << value << endl;
number++;
sum += value;
}
calculateStats(sum, number);
inputFile.close();
}
void calculateStats(double sum, int number)
{
average = sum / number;
cout << "sum; " << sum << " average " << average;
}
void saveResults()
{
}
|
Last edited on
You don't have a 2d array.
On line 27: count << ARRAY_SIZE // wrong <<
change to count < ARRAY_SIZE // correct <
Topic archived. No new replies allowed.