Thread: Finding numbers higher than the first element in array

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    54

    Finding numbers higher than the first element in array

    I need help with this program. I'm trying to report all the numbers higher than the first element of the array that the user inputs. It only prints some of the elements higher than the first element but not all of them. Can someone please help me to fix this program?

    Code:
    #include <iostream.h>
    
    int main()
    {
    	// declare variables
    	float a[10];
    	int hold;
    	
    	// get floats from user
    	cout << "What are the floating point numbers?" << endl;
    	
    	for(int i = 0; i < 10; i ++)
    	{
    		cin >> a[i];
    	}
    	
    	// find which numbers have exceeded first elemnet
    	cout << "Numbers that exceed the first element : ";
    	for (int j = 0; j < 10; j++)
    {
    	if (a[j] > a[1])
    	{
    		cout << a[j] << " ";
    	}
    }
    
    	cin >> hold;
    	return 0;
    	
    }

  2. #2
    lurker
    Guest
    The first element in your array is a[0], not a[1]. Try that and see if it works.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    54
    Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. count/display non-repeated element of array
    By azsquall in forum C++ Programming
    Replies: 15
    Last Post: 07-10-2008, 09:42 AM
  2. Finding mode in array of numbers
    By Snowcat in forum C++ Programming
    Replies: 1
    Last Post: 01-16-2006, 09:58 PM
  3. finding the element number in an array
    By tommy69 in forum C Programming
    Replies: 7
    Last Post: 04-02-2004, 04:26 AM
  4. getting numbers in an array
    By ct26torr in forum C Programming
    Replies: 6
    Last Post: 03-04-2003, 10:31 AM
  5. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM