Array Errors HELP PLEASE

Some errors in my program. NEED HELP

Page 1 of 1

1 Replies - 415 Views - Last Post: 06 December 2009 - 04:07 PM Rate Topic: -----

#1 Retro Batman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-November 09

Array Errors HELP PLEASE

Posted 06 December 2009 - 03:19 PM

I'm trying to write a program that will allow the user to enter a file name and then use that file to calculate
the total, average, highest, lowest, and sort the data. I am having some errors and i don't know how to fix them.

Here is my code

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

// Prototypes
int readData(int [], int);
void sortArray(int [], int);
void showArray(int [], int);
int getLowest(int [], int);
int getHighest(int [], int);
float findTotal(float [], int, float &, float &);

int main()
{
	const int size = 50;
	int highest, lowest;
	int numbers[size];
	float avg, total;
	
	readData(numbers, size);
	cout << "There are " << count << "number(s) in the file." << endl;
	
	sortArray(numbers, size);
	
	getHighest(numbers, size);
	cout << "The highest number is: " << highest << endl;
	
	getLowest(numbers, size);
	cout << "The lowest numeber is: " << lowest << endl;
	
	findTotal(numbers, size)
	cout << "The total is: " << total << endl;
	cout << "The Average is: " << avg << endl;
	}


int readData (int numbers[], int size)
{
	const int name_size = 31;
	int numbers[size];	 
	int count;						 
	ifstream inputFile;			 // Input file stream object
	char filename[name_size];
	
	cout << "Please enter the file name: " << endl;
	cin >> setw(name_size) >> filename;
	
	inputFile.open(filename); // Open the file.
	if (!inputFile)
	{
		cout << "Error opening the file!" << endl;
		exit(190)
	
	// Read the numbers from the file into the array.
	for (count = 0; count < size; count++)
		inputFile >> numbers[count];
	
	// Close the file.
	inputFile.close();
		
		return count;
}
	

// Sort the Array
void sortArray(int numbers[], int size)
	{
		bool swap;
		int temp;
		
		do
		{
			swap = false;
			for (int count = 0; count < (size - 1); count++)
			{
				if (numbers[count] > numbers[count + 1])
				{
					temp = numbers[count];
					numbers[count] = numbers[count + 1];
					numbers[count + 1] = temp;
					swap = true;
				}
			}
		} while (swap);
	}

// Print the Sorted Array	
void showArray(int numbers[], int size)
	{
		cout << "Your Numbers are: ";
		for (int count = 0; count < size; count++)
			cout << numbers[count] << " ";
		cout << endl;
	}
	

// Highest Function	
int getHighest(int numbers[], int size)
	{
		int count;
		int highest;
		highest = numbers[0];
		for (count = 1; count < size; count++)
		{
			if (numbers[count] > highest)
			highest = numbers[count];
		}
		return highest;
	}
	
// Lowest Function
int getLowest(int numbers[], int size)
	{
		int count;
		int lowest;
		lowest = numbers[0];
		for (count = 1; count < size; count++)
		{
			if (numbers[count] < lowest)
			lowest = numbers[count];
		}	
		return lowest;
	}
	
// Total and Average function
float findTotal(float numbers[], int count, float &total, float &avg)
	{
		for(int count = 0, count < size, count++)
			total += numbers[count];
			avg = total / count;
	return;
	}



First error is here

readData(numbers, size);
	cout << "There are " << count << "number(s) in the file." << endl;

Where the error is no match for opporator


Second error is here

  findTotal(numbers, size); 

The error is in the call here. Say cant convert int to float.


Third

int readData (int numbers[], int size)
{



The error is when im writing the function it says "a function deffiniton is not allowed here" this happens before all
my functions.
There are some small errors too that i cant find

Please help
Thanks

This post has been edited by Retro Batman: 06 December 2009 - 03:23 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Array Errors HELP PLEASE

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Array Errors HELP PLEASE

Posted 06 December 2009 - 04:07 PM

And where would you be getting count from in main? How are highest, lowest, total, and avg getting set in main?

and your call to findTotal does not match the prototype and is lacking a terminating semicolon.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1