2 Replies - 4859 Views - Last Post: 10 November 2010 - 07:39 AM Rate Topic: -----

#1 Vls610  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 29-March 10

Highest and Lowest in an Array.

Posted 10 November 2010 - 07:04 AM

The objective of the program is to to find the highest and lowest number in an array, along with the average. However I am stuck on figuring out this error this error with the find highest and lowest number in the array.

The error that keeps appearing is: invalid types `int[int]' for array subscript.

If anyone can explain to me what this means, or what I might be doing wrong it would be greatly appreciated.

       

#include <iostream>   //cin, cout
#include <iomanip> 
#include <cmath>  
#include <string> //setw, setprecision, fixed
#include <fstream> // File stream thingy

using namespace std;  //using the standard names
const int ARRAYSIZE= 30;  
int highestprice (int number);
int lowestprice (int number );
double averageitems ();


int main()
{
    int numbers[ARRAYSIZE];	 
	int count;	

ifstream inputFile; 
   inputFile.open ("lab11data.dat"); //open in file
    if (!inputFile)
     {
      cout << "File did not open properly!"<< endl;
      system ("Pause");
      exit(EXIT_FAILURE); 
      }
      
for (count = 0; count < ARRAYSIZE; count++) // if count less then array add 1
   {
		inputFile >> numbers[count];             //read from file
       }
         inputFile.close();
         
    cout << "The numbers are: ";
for (count = 0; count < ARRAYSIZE; count++)
   {
		cout << numbers[count] << " "<< endl;
	    }


 system ("pause"); 
 return 0 ; 
    
}

int highestprice (int numbers)
{ 
  
  int count; 
  int highest;

   highest = numbers[0];      //initialize highest to the 1st array element
   for (count = 1; count < ARRAYSIZE; count++)
    {
     if (numbers[count] > highest)
      highest = numbers[count];
      }
}
int lowestprice (int numbers)
{
    int count; 
    int lowest;

    lowest = numbers[0];       //initialize lowest to the 1st array element
     for (count = 1; count < ARRAYSIZE; count++)
      {
        if (numbers[count] < lowest)
         lowest = numbers[count];
       }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Highest and Lowest in an Array.

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Highest and Lowest in an Array.

Posted 10 November 2010 - 07:22 AM

You are supposed to be sending arrays of ints to the functions, so, for example, the signature of highestprice should be:
int highestprice (int numbers[])

or
int highestprice (int *numbers)


Also change the prototypes accordingly.
Was This Post Helpful? 0
  • +
  • -

#3 Vls610  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 29-March 10

Re: Highest and Lowest in an Array.

Posted 10 November 2010 - 07:39 AM

I just noticed the error about 10 minutes after I posted this, lol.
Thank you very much for your help, and for the tip about changing my prototypes.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1