2 questions first did you guys get hacked yesterday or something and 2nd:

Not sure what I am doing wrong but have an issue with a program...i am to input a file name that i have in my project and it is not doing it right...

This is what my program should look like for each textfile...

Sample Output 1
Enter the file to read in: data1.txt
The numbers in the array are:

45.3 57.4 23.6 34.2
234.6 34.9 54.8 934.9
8432.5 9809.3 539.7 43.9
12.0


The numbers in the array are:

12.0 23.6 34.2 34.9
43.9 45.3 54.8 57.4
234.6 539.7 934.9 8432.5
9809.3


The average of the numbers is 1558.2
The median of the numbers is 54.8

Press any key to continue


What I am getting is...

Enter the file to read in: data1.txt

The numbers in the array are:

The average of the numbers is 45
The median of the numbers is 0

Press any key to continue...

Not sure what I am doing wrong any help would mean alot

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

const int MAX_SIZE = 100;

void Fill_Array(int Size[], int& count, int& numbers_used);
void Print_Array(int Size[], int count);
double Calc_Average(int Size[], double average);
void Sort(int Size[], int numbers_used);
void Swap(int& v1, int& v2);
int index_of_smallest(const int Size[], int start_index, int number_used);
int Calc_Median(int median, int Size[]);
void Print_Array_and_Calculations(int median, double average);

int main()
{
	ifstream in_size;
	int count;
	int Size [MAX_SIZE],
	    numbers_used = 0,
	    median = 0;
	double average = 0.0;

	Fill_Array(Size, count, numbers_used);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, numbers_used);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(int Size[], int& count, int& numbers_used)
{
	int size;
	ifstream in_size;
	string text_file;
	
	
	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << endl << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(int Size[], int count)
{
	int number_used = 0;
	for(int index = 0; index < number_used; index++)
		cout << Size[index] << " ";
}

double Calc_Average(int Size[], double average)
{
	int total = 0;
	for (int i = 0; i < MAX_SIZE; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / MAX_SIZE;

	return average;
}

void Sort(int Size[], int number_used)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < number_used - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, number_used);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(int& v1, int& v2)
{
	int temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

int index_of_smallest(const int Size[], int start_index, int number_used)
{
	int min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

int Calc_Median(int median, int Size[])
{
	median = Size [ MAX_SIZE / 2 ];
	return median;
}

void Print_Array_and_Calculations(int median, double average)
{
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;

Recommended Answers

All 34 Replies

Does anybody ever bother to review their posts before pressing submit???
Code tags!!!!!

no disrespect just made a mistake...sorry

Look closely at your Print_Array function in lines 67 - 72. You pass this function a variable called count, but you never use it. You declare a new variable called number_used and assign it a value of 0. Then you have this loop:

int number_used = 0;
for(int index = 0; index < number_used; index++)
     cout << Size[index] << " ";

This loop is the same as this:

for(int index = 0; index < 0; index++)
     cout << Size[index] << " ";

index will never be less than 0, so this line:

cout << Size[index] << " ";

never gets executed.

You want to get rid of the variable number_used and replace it with count in your loop, assuming count is the number of elements in the array and that you want to display all of those elements.

not sure if I did this right or not but returning alot of errors:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(int Size[], int& count, int& tempcount);
void Print_Array(int Size[], int count);
double Calc_Average(int Size[], double average);
void Sort(int Size[], int tempcount);
void Swap(int& v1, int& v2);
int index_of_smallest(const int Size[], int start_index, int tempcount);
cout << "The numbers in the array are: " << endl << Size[start_index] << endl;
int Calc_Median(int median, int Size[]);
void Print_Array_and_Calculations(int median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int Size[MAX_SIZE],
	    tempcount = 0,
	    median = 0;
	double average = 0.0;

	Fill_Array(Size, count, tempcount);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, tempcount);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(int Size[], int& count, int& tempcount)
{
	int size;
	ifstream in_size;
	string text_file;
	
	
	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << endl << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(int Size[], int count)
{
	int tempcount = 1;

	for(int index = 0; index < MAX_SIZE; index++)
		cout << Size[index] << " ";

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);

	if (tempcount == 4)
	{
		cout << endl;
		tempcount = 1;
	}
	else
	tempcount++;
}

double Calc_Average(int Size[], double average)
{
	int total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(int Size[], int tempcount)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < tempcount - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, tempcount);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(int& v1, int& v2)
{
	int temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

int index_of_smallest(const int Size[], int start_index, int tempcount)
{
	int min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < tempcount; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

int Calc_Median(int median, int Size[])
{
	median = Size [ MAX_SIZE / 2 ];
	return median;
}

void Print_Array_and_Calculations(int median, double average)
{
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

Instructions:

Write a program that allows the user to enter a filename and then puts all of the numbers into an array. It will print the array, sort the array, find the average of all of the numbers, find the median of all of the numbers, and print the sorted array and all of the answers. The array should not hold more than 100 numbers (this is the MAX_SIZE)

Below are the functions and a description of what they should do
Fill_Array – This function allows the user to type in a filename, open the file and checks to see if it opened correctly. It then puts all numbers into an array, and keeps count of how many numbers are entered. It should make sure that it doesn’t fill more than the MAX_SIZE of the array.
Print_Array - Prints all of the numbers in the array, 4 per line with one decimal point
Calc_Average – This function returns the average of all of the numbers in the array.
Sort - This function sorts the array. After this function is executed, the numbers in the array will be sorted. The order of the original array will be gone. It calls the function Swap to swap two integers in the array. If you want to call more functions from within this function, you can.
Swap – This function accepts two integers as it formal parameters and exchanges their values.
Calc_Median – This function returns the median number. The numbers must be sorted to find the median number. The median number is the number in the middle. For example, if the numbers were 75, 78, 80, 89, and 99 the median number would be an 80. If the numbers were 65, 68, 72, and 98, the median number would be the average of the two middle numbers (68 and 72) so the median would be 70. THERE IS NO LOOP IN THIS FUNCTION!!!
Print_Array_and_Calculations – This function prints the array (by calling Print_Array) and then prints the average and the median.

Note: main consists of 6 function calls, and some declarations. There is no loop in main.

not sure if I did this right or not but returning alot of errors:

void Print_Array(int Size[], int count)
{
	int tempcount = 1;

	for(int index = 0; index < MAX_SIZE; index++)
		cout << Size[index] << " ";

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);

	if (tempcount == 4)
	{
		cout << endl;
		tempcount = 1;
	}
	else
	tempcount++;
}

You're still not doing anything with count in this function, so either use it or don't pass it to the function. tempcount has absolutely no effect on anything in this function, so you can delete all the code associated with it. I don't see the purpose of lines 8 through 10 either. You had a decent skeleton in your last post for this function. Go back to it and use the count variable in your loop and see what happens.

the reason for me to use tempcount just is a way to set the rows and columns up so only 4 are printed on each line...so that part is actually working so I think I will need to keep it...the problem with my loop is that it is not taking a decimal point for the first number and is just repeating that number

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(int Size[], int& count);
void Print_Array(int Size[], int count);
double Calc_Average(int Size[], double average);
void Sort(int Size[], int numbers_used);
void Swap(int& v1, int& v2);
int index_of_smallest(const int Size[], int start_index, int number_used);
int Calc_Median(int median, int Size[]);
void Print_Array_and_Calculations(int median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int Size[MAX_SIZE],
	    numbers_used = 0,
	    median = 0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, numbers_used);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(int Size[], int& count)
{
	int size;
	ifstream in_size;
	string text_file;
	
	
	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << endl << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(int Size[], int count)
{
	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
		cout << Size[i] << " ";
		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
		}
		else
			tempcount++;
	}
}

double Calc_Average(int Size[], double average)
{
	int total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(int Size[], int number_used)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < number_used - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, number_used);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(int& v1, int& v2)
{
	int temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

int index_of_smallest(const int Size[], int start_index, int number_used)
{
	int min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

int Calc_Median(int median, int Size[])
{
	median = Size [ MAX_SIZE / 2 ];
	return median;
}

void Print_Array_and_Calculations(int median, double average)
{
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

the reason for me to use tempcount just is a way to set the rows and columns up so only 4 are printed on each line...so that part is actually working so I think I will need to keep it...the problem with my loop is that it is not taking a decimal point for the first number and is just repeating that number

void Fill_Array(int Size[], [B]int[/B]& count);
void Print_Array([B]int[/B] Size[], int count);
double Calc_Average([B]int[/B] Size[], double average);
void Sort([B]int[/B] Size[], int numbers_used);
void Swap([B]int[/B]& v1, [B]int[/B]& v2);
int index_of_smallest(const [B]int[/B] Size[], int start_index, int number_used);
int Calc_Median([B]int[/B] median, int Size[]);
void Print_Array_and_Calculations([B]int[/B] median, double average);

void Fill_Array([B]int[/B] Size[], int& count)
{
	[B]int[/B] size;
	ifstream in_size;
	string text_file;
	
	
	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << endl << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

You have everything declared as integers. If your input does not consist only of integers (which I just noticed that it does not), you'll need to change your variables from integers to doubles or floats. Your input stream is never going to get past that first decimal point since it is looking for integers only and thus you are going to get stuck on this line:

in_size >> size;

size is declared as an integer, so in_size won't look past that first decimal point and you'll just keep getting that first integer before the decimal point over and over again.

I got them to come out but for some reason when i set the precision it doesnt show the decimal point

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(int Size[], int& count);
void Print_Array(int Size[], int count);
double Calc_Average(int Size[], double average);
void Sort(int Size[], int numbers_used);
void Swap(int& v1, int& v2);
int index_of_smallest(const int Size[], int start_index, int number_used);
int Calc_Median(int median, int Size[]);
void Print_Array_and_Calculations(int median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int Size[MAX_SIZE],
	    numbers_used = 0,
	    median = 0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, numbers_used);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(int Size[], int& count)
{
	double size;
	ifstream in_size;
	string text_file;


	
	
	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << endl << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(int Size[], int count)
{

	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);
		cout << Size[i] << " ";
		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
		}
		else
			tempcount++;
	}
}

double Calc_Average(int Size[], double average)
{
	int total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(int Size[], int number_used)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < number_used - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, number_used);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(int& v1, int& v2)
{
	int temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

int index_of_smallest(const int Size[], int start_index, int number_used)
{
	int min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

int Calc_Median(int median, int Size[])
{
	median = Size [ MAX_SIZE / 2 ];
	return median;
}

void Print_Array_and_Calculations(int median, double average)
{
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

I think my only issues from the instructions are setting up my widths(not sure how to do that with an array), the decimal point I seem to be missing, and the sort from smallest to largest...if anyone could explain these final things to me I would appreciate it...

instructions are:

Write a program that allows the user to enter a filename and then puts all of the numbers into an array. It will print the array, sort the array, find the average of all of the numbers, find the median of all of the numbers, and print the sorted array and all of the answers. The array should not hold more than 100 numbers (this is the MAX_SIZE)

Below are the functions and a description of what they should do
Fill_Array – This function allows the user to type in a filename, open the file and checks to see if it opened correctly. It then puts all numbers into an array, and keeps count of how many numbers are entered. It should make sure that it doesn’t fill more than the MAX_SIZE of the array.
Print_Array - Prints all of the numbers in the array, 4 per line with one decimal point
Calc_Average – This function returns the average of all of the numbers in the array.
Sort - This function sorts the array. After this function is executed, the numbers in the array will be sorted. The order of the original array will be gone. It calls the function Swap to swap two integers in the array. If you want to call more functions from within this function, you can.
Swap – This function accepts two integers as it formal parameters and exchanges their values.
Calc_Median – This function returns the median number. The numbers must be sorted to find the median number. The median number is the number in the middle. For example, if the numbers were 75, 78, 80, 89, and 99 the median number would be an 80. If the numbers were 65, 68, 72, and 98, the median number would be the average of the two middle numbers (68 and 72) so the median would be 70. THERE IS NO LOOP IN THIS FUNCTION!!!
Print_Array_and_Calculations – This function prints the array (by calling Print_Array) and then prints the average and the median.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(int Size[], int& count);
void Print_Array(int Size[], int count);
double Calc_Average(int Size[], double average);
void Sort(int Size[], int numbers_used);
void Swap(int& v1, int& v2);
int index_of_smallest(const int Size[], int start_index, int number_used);
int Calc_Median(int median, int Size[]);
void Print_Array_and_Calculations(int median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int Size[MAX_SIZE],
	    numbers_used = 0,
	    median = 0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, numbers_used);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(int Size[], int& count)
{
	double size;
	ifstream in_size;
	string text_file;

	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(int Size[], int count)
{

	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);
		cout << Size[i] << " ";
		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
		}
		else
			tempcount++;
	}
}

double Calc_Average(int Size[], double average)
{
	int total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(int Size[], int number_used)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < number_used - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, number_used);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(int& v1, int& v2)
{
	int temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

int index_of_smallest(const int Size[], int start_index, int number_used)
{
	int min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

int Calc_Median(int median, int Size[])
{
	median = Size [ MAX_SIZE / 2 ];
	return median;
}

void Print_Array_and_Calculations(int median, double average)
{
	cout << endl << endl << endl << "The numbers in the array are:" << endl;
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

the sort from smallest to largest

See the comment below ...

int main()
{
    int count;
    numbers_used = 0,

    <snip>

    // You are passing numbers_used, which is zero,
    // shouldn't you be using [B]count[/B] instead here?
    Sort(Size, numbers_used);
}

What do you mean by "setting up my widths" ?

from the instructions can anyone give me an idea where and how to print this smallest to largest in my program and also the decimal point issue...i think it has something to do in

Size[count] = size;

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(int Size[], int& count);
void Print_Array(int Size[], int count);
double Calc_Average(int Size[], double average);
void Sort(int Size[], int count);
void Swap(int& v1, int& v2);
int index_of_smallest(const int Size[], int start_index, int number_used);
int Calc_Median(int median, int Size[]);
void Print_Array_and_Calculations(int median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int Size[MAX_SIZE],
	    numbers_used = 0,
	    median = 0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, count);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(int Size[], int& count)
{
	double size;
	ifstream in_size;
	string text_file;

	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(int Size[], int count)
{

	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);
	cout << Size[i] << " ";

		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
		}
		else
			tempcount++;
	}
}

double Calc_Average(int Size[], double average)
{
	int total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(int Size[], int count)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < count - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, count);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(int& v1, int& v2)
{
	int temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

int index_of_smallest(const int Size[], int start_index, int number_used)
{
	int min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

int Calc_Median(int median, int Size[])
{
	median = Size [ MAX_SIZE / 2 ];
	return median;
}

void Print_Array_and_Calculations(int median, double average)
{
	cout << endl << endl << endl << "The numbers in the array are:" << endl;
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

You have a potential array-out-of-bounds condition there, you should change

in_size >> size;
while((!in_size.eof()) && (count <= MAX_SIZE))

to

while((in_size >> size) && (count [B]<[/B] MAX_SIZE))

are you positive because I want to print some negative numbers as well and after doing so that negative numbers were removed....this is my input files.....

data2.txt:

54.654 -7.435 345.53 -945.32 134.65
324.3
456.974 -764.45 2845.493 43.54 75.3 3468.4 -6
-652.7

data1.txt:

45.34 57.4 23.6
34.2 234.643 34.86
54.76 934.85 8432.5 9809.3 539.732 43.92
12

what I had before was working but it just did not have the decimal point which is something I am trying to find out

are you positive because I want to print some negative numbers as well and after doing so that negative numbers were removed....this is my input files.....

data2.txt:

54.654 -7.435 345.53 -945.32 134.65
324.3
456.974 -764.45 2845.493 43.54 75.3 3468.4 -6
-652.7

data1.txt:

45.34 57.4 23.6
34.2 234.643 34.86
54.76 934.85 8432.5 9809.3 539.732 43.92
12

what I had before was working but it just did not have the decimal point which is something I am trying to find out

Jim, reread my post 10. If your data has decimal points in it, don't declare your array as an array of integers. Declare it as an array of doubles. You say it's working? It shouldn't be reading in the data correctly if you are trying to read in doubles as integers.

are you positive

You are using count as an index into the Size array, which holds at max MAX_SIZE items, so
you must not allow: Size[MAX_SIZE] = somevalue; to happen, that would be out-of-bounds.

so pretty much just change int Size[]

to

double Size[] at every place and it should show the decimal

so pretty much just change int Size[]

to

double Size[] at every place and it should show the decimal

Some other places too, like the Swap() function has to be changed to operate with doubles, and whereever you assign a value from Size[at_some_index] to a variable, change the variable receiving the value from int to double.

Before I forget just wanna say thanks for everyone helping me but now I have an error I have never seen before...actually four of them

1>c:\documents and settings\don & diane kruep\desktop\project 6\p06.cpp(110) : error C2108: subscript is not of integral type
1>c:\documents and settings\don & diane kruep\desktop\project 6\p06.cpp(124) : error C2108: subscript is not of integral type
1>c:\documents and settings\don & diane kruep\desktop\project 6\p06.cpp(127) : error C2108: subscript is not of integral type
1>c:\documents and settings\don & diane kruep\desktop\project 6\p06.cpp(129) : error C2108: subscript is not of integral type


all meaning the same thing obviously....is this something to do with my doubles??

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(double Size[], int& count);
void Print_Array(double Size[], int count);
double Calc_Average(double Size[], double average);
void Sort(double Size[], int count);
void Swap(double& v1, double& v2);
double index_of_smallest(const double Size[], int start_index, int number_used);
double Calc_Median(double median, double Size[]);
void Print_Array_and_Calculations(double median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int numbers_used = 0;
	double Size[MAX_SIZE];
	double median = 0.0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, count);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(double Size[], int& count)
{
	double size;
	ifstream in_size;
	string text_file;

	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((in_size >> size) && (count < MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(double Size[], int count)
{

	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);
	cout << Size[i] << " ";

		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
		}
		else
			tempcount++;
	}
}

double Calc_Average(double Size[], double average)
{
	double total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(double Size[], int count)
{
	double index_of_next_smallest;
	
	for (int index = 0; index < count - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, count);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(double& v1, double& v2)
{
	double temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

double index_of_smallest(const double Size[], double start_index, int number_used)
{
	double min = Size[start_index],
		index_of_min = start_index;
	for (double index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

double Calc_Median(double median, double Size[])
{
	median = Size[ MAX_SIZE / 2 ];

	return (median);
}

void Print_Array_and_Calculations(double median, double average)
{
	cout << endl << endl << endl << "The numbers in the array are:" << endl;
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

>> all meaning the same thing obviously....is this something to do with my doubles??

That error comes when you try to do something like the following:

double anArray[100];
[B]double[/B] index = 0;
anArray[index] = 0.123;

The variable index cannot be of non-integral type (double, float), so you must change those four lines back and use int type for indexes. Just think of it, e.g Array[5.5984] does not make sense.

ughhh this program will never end...ok I got those errors away but now have a conversion from double to int warning and a fatal error warning....sorry I know I am probably driving you crazy right now

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(double Size[], int& count);
void Print_Array(double Size[], int count);
double Calc_Average(double Size[], double average);
void Sort(double Size[], int count);
void Swap(double& v1, double& v2);
double index_of_smallest(const double Size[], int start_index, int number_used);
double Calc_Median(double median, double Size[]);
void Print_Array_and_Calculations(double median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int numbers_used = 0;
	double Size[MAX_SIZE];
	double median = 0.0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, count);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(double Size[], int& count)
{
	double size;
	ifstream in_size;
	string text_file;

	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((in_size >> size) && (count < MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;
	}
	in_size.close();
}

void Print_Array(double Size[], int count)
{

	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);
	cout << Size[i] << " ";

		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
		}
		else
			tempcount++;
	}
}

double Calc_Average(double Size[], double average)
{
	double total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(double Size[], int count)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < count - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, count);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(double& v1, double& v2)
{
	double temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

double index_of_smallest(const int Size[], int start_index, int number_used)
{
	double min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

double Calc_Median(double median, double Size[])
{
	median = Size[ MAX_SIZE / 2 ];

	return (median);
}

void Print_Array_and_Calculations(double median, double average)
{
	cout << endl << endl << endl << "The numbers in the array are:" << endl;
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

There is one int -> double modification to do, you have
double index_of_smallest(const int Size[], int start_index, int number_used)
change it to
double index_of_smallest(const double Size[], int start_index, int number_used)

I think that should do it.

ok thank you so much that worked...I have two final things to figure out on my program but you really dont havta help me if you don't wanna because you helped me a ton already but my issues are just two simple ones im hoping...first I need the array to line up so all the decimal points are exactly lines up in the columns...kinda starting on it but just can't it completed and the other issue is the sorting from smallest to largest does not output yet which probably is the reason the median and average are not working

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(double Size[], int& count);
void Print_Array(double Size[], int count);
double Calc_Average(double Size[], double average);
void Sort(double Size[], int count);
void Swap(double& v1, double& v2);
double index_of_smallest(const double Size[], int start_index, int number_used);
double Calc_Median(double median, double Size[]);
void Print_Array_and_Calculations(double median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int numbers_used = 0;
	double Size[MAX_SIZE];
	double median = 0.0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	average = Calc_Average(Size, average);
	Sort(Size, count);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(double Size[], int& count)
{
	double size;
	ifstream in_size;
	string text_file;

	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;

	}
	in_size.close();
}

void Print_Array(double Size[], int count)
{

	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);
			
	
	cout << Size[i] << " ";

		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
			cout << setw(15) << "" << setw(18) << "" << setw(21) << "" << setw(26) << "";
			cout.setf(ios::right);
		}
		else
		tempcount++;
	}
}

double Calc_Average(double Size[], double average)
{
	double total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(double Size[], int count)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < count - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, count);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(double& v1, double& v2)
{
	double temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

double index_of_smallest(const double Size[], int start_index, int number_used)
{
	double min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

double Calc_Median(double median, double Size[])
{
	median = Size[ MAX_SIZE / 2 ];

	return (median);
}

void Print_Array_and_Calculations(double median, double average)
{
	cout << endl << endl << endl << "The numbers in the array are:" << endl;
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}

i think i got the sorting from smallest to largest somewhat right but can someone look at my changes and show me what I am still not doing correctly.....

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void Fill_Array(double Size[], int& count);
void Print_Array(double Size[], int count);
double Calc_Average(double Size[], double average);
void Sort(double Size[], int count);
void Swap(double& v1, double& v2);
double index_of_smallest(const double Size[], int start_index, int number_used);
double Calc_Median(double median, double Size[]);
void Print_Array_and_Calculations(double median, double average);

const int MAX_SIZE = 100;

int main()
{
	ifstream in_size;
	int count;
	int numbers_used = 0;
	int small_index;
	double Size[MAX_SIZE];
	double median = 0.0;
	double average = 0.0;

	Fill_Array(Size, count);
	Print_Array(Size, count);
	small_index = index_of_smallest(Size, count, numbers_used);
	cout << Size[small_index] << endl;
	average = Calc_Average(Size, average);
	Sort(Size, count);
	Calc_Median(median, Size);
	Print_Array_and_Calculations(median, average);
	
	in_size.close();
	return 0;
}

void Fill_Array(double Size[], int& count)
{
	double size;
	ifstream in_size;
	string text_file;

	cout << "Enter the file to read in: ";
	getline(cin, text_file);
	
	cout << "The numbers in the array are:" << endl << endl;
	in_size.open (text_file.c_str ());
	if(in_size.fail())
	{
		cerr  << "Error opening file" << endl;
		exit(1);
	}
	count = 0;
	in_size >> size;
	while((!in_size.eof()) && (count <= MAX_SIZE))
	{
		Size[count] = size;
		count++;
		in_size >> size;

	}
	in_size.close();
}

void Print_Array(double Size[], int count)
{

	int tempcount = 1;
	for(int i = 0; i < count; ++i)
	{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(1);
			
	
	cout << Size[i] << " ";

		if (tempcount == 4)
		{
			cout << endl;
			tempcount = 1;
			cout << setw(15) << "" << setw(18) << "" << setw(21) << "" << setw(26) << "";
			cout.setf(ios::right);
		}
		else
		tempcount++;
	}
}

double Calc_Average(double Size[], double average)
{
	double total = 0;
	for (int i = 0; i < 100; i++)
	{
		total = total + Size[i];
	}
	average = double(total) / 100;

	return average;
}

void Sort(double Size[], int count)
{
	int index_of_next_smallest;
	
	for (int index = 0; index < count - 1; index++)
	{
		index_of_next_smallest = index_of_smallest(Size, index, count);
		Swap(Size[index], Size[index_of_next_smallest]);
	}
}

void Swap(double& v1, double& v2)
{
	double temp;
	temp = v1;
	v1 = v2;
	v2 = temp;
}

double index_of_smallest(const double Size[], int start_index, int number_used)
{
	double min = Size[start_index],
		index_of_min = start_index;
	for (int index = start_index + 1; index < number_used; index++)
		if(Size[index] < min)
		{
			min = Size[index];
			index_of_min = index;
		}
		return index_of_min;
}

double Calc_Median(double median, double Size[])
{
	median = Size[ MAX_SIZE / 2 ];

	return (median);
}

void Print_Array_and_Calculations(double median, double average)
{
	cout << endl << endl << endl << "The numbers in the array are:" << endl;
	cout << endl << "The average of the numbers is " << average;
	cout << endl << "The median of the numbers is " << median;
	cout << endl << endl;
}
double Calc_Median(double median, double Size[])
{
        // You must use the effective count of items currently in the array,
        // instead of the constant MAX_SIZE
	median = Size[ MAX_SIZE / 2 ];
	return (median);
}

median = Size[ MAX_SIZE / 2 ];
return (median);


so it would be median =Size[count /2]
return median;

also I get two warnings of possible loss of data that is my other main issue

median = Size[ MAX_SIZE / 2 ];
return (median);


so it would be median =Size[count /2]
return median;

That's better, but does the function know what count's value is? You don't accept count as a parameter:

double Calc_Median(double median, double Size[])
{
        // You must use the effective count of items currently in the array,
        // instead of the constant MAX_SIZE
	median = Size[ MAX_SIZE / 2 ];
	return (median);
}

You pass this function median. I don't see any reason for this function to need median. It's calculating it after all and you are immediately overwriting the value, so whatever you passed it is gone. This function DOES need count though, but it does not have count. Change it so it receives count, not median. Change the function call in line 35 so that it passes count to the function, not median.

also I get two warnings of possible loss of data that is my other main issue

You need to tell us what code these warnings are associated with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.