Helpp!!!

hey everyone,
so i need help. we're suppose to write a program that reads a file of odd values and another of even values and calculte the mean and median of each file.
i'm very new to all this so i dont even know where to start. Please healppppp
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

ifstream input_stream;
ofstream output_stream;

void fillArray (double values_array[], int array_size, int& length);
void bubbleSort (double values_array[], int length);
double calcMedian (double values_array[], int array_size);
double calcMean (double values_array[], int array_size, int length);

int main()
{
double values_array[array_size];
int length;
fillArray (values_array);
bubbleSort (values_array, length);




input_stream.open ("FileA.txt");
if (input_stream.fail())
cout<< "Input file opening failed. \n";
exit(1);

}


void fillArray(double values_array[], int array_size, int& length)
{
int index = 0;
double nextValue;

input_stream >> nextValue;

while ((nextValue > 0) && (index < array_size))
{
values_array[index] = nextValue;
index++;
input_stream >> nextValue;
}

values_array[index] = 0;
length = index;

void bubbleSort(double values_array[], int length)
{
for (int i = length - 1; i > 0; i--)
for (int j = 0; j < i; j++)
if (values_array[j] > values_array[j+1])
{
int temp = values_array[j+1];
values_array[j+1] = values_array[j];
values_array[j] = temp;
}



double (double values_array[], int array_size);
{
if ((array_size % 2) == 0)
{
median = (bubbleSort [array_size/2] + sorted [(array_size/2) -1])/ 2.0;

else{
median = bubbleSort[array_size/2];

}


double calcMean (double values_array[], int array_size, int length);
double sum = values_array [0];
for (int length = 1; length < array_size; ++i){
sum += values_array[i];
}
return sum/array_size;

}


int main()
{

I am really lost! sorry if i angered you but i wasn't trying to get my hw done by someone else, i'm trying to figure this out. i also have to understand this because i have to write an IPO.

I didnt close the file yet, i'm going to do that in a separate output_func
Last edited on
First a note: use code tags and intuitive indentation when posting code. It really helps reading and commenting:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ifstream input_stream; // global variables.  Avoid them. Pass locals by reference to functions instead.
ofstream output_stream;

void fillArray (double values_array[], int array_size, int& length);
void bubbleSort (double values_array[], int length);
double calcMedian (double values_array[], int array_size);
double calcMean (double values_array[], int array_size, int length);
// length here, array_size there. used inconsistently

int main()
{
  double values_array[array_size]; // What is array_size? It must be a compile-time const.
  int length;
  fillArray (values_array); // no file is open yet. Does the argument-list match function's declaration?
  bubbleSort (values_array, length);
  input_stream.open ("FileA.txt"); // too late
  if ( input_stream.fail() )
    cout<< "Input file opening failed. \n"; // only statement within if

  exit(1);  // return 1;  exit is harsh and unnecessary
}
Thank you, i had to rewrite everything.
Topic archived. No new replies allowed.