need help with project

I'm getting a few errors. i'm going to copy my code here (errors first, and then the contents of each file). I have tried several times to rid certain errors and then new ones will pop up. ANY help is greatly appreciated...

errors after
make
g++47 -std=c++11 -Wall -Wextra -I. -I/home/courses/cop3330p/LIB/cpp -c main.cpp
In file included from main.cpp:6:0:
stats.cpp: In function ‘float Median(int*, size_t)’:
stats.cpp:30:9: error: expected primary-expression before ‘int’
stats.cpp:30:28: error: expected primary-expression before ‘size’
stats.cpp:31:3: error: expected ‘;’ before ‘{’ token
stats.cpp:24:9: warning: unused variable ‘Median’ [-Wunused-variable]
stats.cpp:26:7: warning: unused variable ‘middle1’ [-Wunused-variable]
main.cpp:46:1: error: expected ‘}’ at end of input
main.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
In file included from main.cpp:6:0:
stats.cpp: At global scope:
stats.cpp:22:7: warning: unused parameter ‘array’ [-Wunused-parameter]
make: *** [main.o] Error 1
godfrey@linprog3.cs.fsu.edu:~/cop3330/hw2>



here is the stats.h

#ifndef stats
#define stats

float Mean (const int* array,size_t size); //prototype for mean
float Median (int* array,size_t size); //prototype for median
void Sort (int* array,size_t size); //prototype for sort

#endif


_______
stats.cpp

//retreives function prototypes

#include "stats.h"
#include <cstdlib>
#include <math.h>


float Mean (const int* array,size_t size)
{
float total=0;
for(size_t i=0;i<size; i++)
{
total+= array[i]; //count number of elements in the array
}
return (total/size); //gives the value to return to the mean
}

float Median (int* array, size_t size)
{
float Median = 0;
int middle = (size/2) - 1;
int middle1 = middle + 1;

//call on the sort function

Sort(int* array, size_t size)
{
int t;
int j=0;

//using the psuedocode provided for the insertion algorithm,
//sort the elements in the array
for (size_t int i = 1; i < size; i++)
{
t = array[i];
j = i;
while ( j > 0 && array[j-1] > t)
{
array[j]=array[j-1];
j = j - 1;
}
array[j] = t;
}
}

//if the user chooses an even number of elements for the array
//provide the two numbers for the possible median
if(size%2==0)
{
median=(array[middle] + array[middle1])/2.0;
return median;
}
else
{
return array[size/2];
}
}
___________
main.cpp
____________

#include <cstdlib>
#include <iostream>
#include <math.h>
#include "stats.h"
#include "stats.cpp"

using namespace std;



int main()
{
int a[100]; //max size the array can hold
int size=0; //variable to hold the actual size of the array

cout << "Enter the array size: "; //allow user to determine size of the array
cin >> size; //store value for size

cout << "Enter the elements of the array: " << endl;

//The user will now enter elements into the array until the size listed is
//reached
for (size_t int i = 0; i<size; i++)
{

cin >> a[i];
}

//Output the elements in order

cout << "Array includes the following sequence: " << endl;
for (size_t int i=0;i<size; i++)
{
cout << " " << a[i] << " " << endl; //output elements
}
cout << endl;

//Now print the mean and median

cout << "Median: " << Median(a,size) << endl;
cout << "Mean/Average: " << Mean(a, size) << endl;
cout << "Press enter to exit" << endl;
system("pause"); //wait until user to hit enter to complete program
return 0;
}

Last edited on
Make sure the included files compile before you try compile the files that include them. Start with stats.h, then stats.cpp before you try compiling main.cpp.
Last edited on
Don't #include "stats.cpp" , just link the file.
http://www.cplusplus.com/forum/general/113904/#msg622055


you are trying to define the `Sort()' function inside the `Median()' function.
Topic archived. No new replies allowed.