It was suppose to be to a pointer not an array. That is my mistake. However I did get it read in the file and display the output correct. Now I am sorting the numbers, and I run across this error "99 non-lvalue in assignment " when compiling. I am using the most recent up to date version of Dev-C++, I have tried google to find some meaning and come up empty handed. Any here is the code:
CODE
//MODE vs MEDIAN pg.632
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void sortArray1(int *, int );
void showArray1(int *, int );
int main()
{
ifstream file1; //used to read from data file numbers_1
// ifstream file2; //used to read from data file number_2
// ifstream file3; //used to read from data file number_3
const int num_commuters=50; //number of comuters
int mile1[num_commuters];
// int mile2[num_commuters];
// int mile3[num_commuters];
int count;
//open file 1
file1.open("numbers_1.txt");
if (!file1)
cout <<"Error opening file\n";
else
{
for (count=0; count < num_commuters; count++)
file1 >> *(mile1+count);
//open file 2
// file2.open("numbers_2.txt");
// if (!file2)
// cout <<"Error opening file\n";
// else
// {
// for (count=0; count < num_commuters; count++)
// file1 >> *(mile2+count);
//
// //open 3
// file3.open("numbers_3.txt");
// if (!file3)
// cout <<"Error opening file\n";
// else
// {
// for (count=0; count < num_commuters; count++)
// file1 >> *(mile3+count);
//close all files
file1.close();
// file2.close();
// file3.close();
//display output
}
//table
cout <<" Medians : Modes" << endl;
cout <<" _________________________" << endl;
cout <<"File 1 numbers_1.txt" <<" : " << endl;
cout <<"File 2 numbers_2.txt" <<" : " << endl;
cout <<"File 3 numbers_3.txt" <<" : " << endl;
cout << endl;
cout <<"Average Median: " << endl;
cout <<"Average Mode: " << endl <<endl;
cout <<" Orignal List : Sorted List" << endl;
cout <<"__________________________________________________________" << endl;
cout <<"File 1 File 2 File 3 : File 1 File 2 File 3" << endl;
cout <<"______ ______ ______ : ______ ______ ______" << endl;
//see out file 1
for(count =0; count < num_commuters; count++)
{
cout << " " << *(mile1+count) << endl;
}
system ("pause");
return 0;
}
//}
//}
//*****************
//sort the pointer*
//*****************
void sortArray1(int *mile1, int size)
{
int temp;
bool swap;
do
{
swap = false;
for (int count = 0; count < (size -1); count++)
{
if(*mile1+count > *mile1+(count+1))
{
temp = *mile1+count;
*mile1+count = *mile1+(count + 1);
*mile1+(count + 1) = temp;
swap = true;
}
}
}
while (swap);
}
//*****************
//show the pointer*
//*****************
void showArray(int *mile1, int size)
{
for (int count = 0; count < (size-1); count++)
cout << *mile1+count << endl;
}
I am to read 3 file but am only working 1 file at time. My apologies to all of the coded out code. Where did I mess up at? Please leave thoughts and comments. Thanks