Having a little trouble with my first array

This is a discussion on Having a little trouble with my first array within the C++ Programming forums, part of the General Programming Boards category; This program was working fine until i added the highest score function something about local function definitions are illegal??? As ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    29

    Unhappy Having a little trouble with my first array

    This program was working fine until i added the highest score function
    something about local function definitions are illegal???

    As always help is greatly appreciated thanks for any many times over!!

    Code:
    #include <iostream>
    
    using namespace std;
    
    //**********************************************Function prototypes
    void enterScore(int score[]);   
    void averageScore(int score[]);
    void highestScore(int score[]);
     
    //**********************************************Function main
    void main()
    {
    	int score[5];
    
    enterScore(score);
    averageScore(score);
    highestScore(score);
    
    }
    
    //*************************enter score function********************************************
    
    void enterScore(int grade[])
    	{
    	for (int x = 0; x<5; x++)
    {
    	cout << "\nEnter score #"<<" ";
    	cin >> grade[x];
    		
    	}
    }
    
    //**************************average score function*******************************************
    void averageScore(int num[])
    {
    	int tot = 0;
    	int avg = 0;
    
    	for (int x=0; x<5; x++)     
    	
    		tot+=num[x];
    
    		avg = tot/5;
    
    	cout <<"\n" << tot <<" is the total of the test scores. "<<"\n";
    	cout <<"\n" << avg <<" is the average test score. "<<"\n";
    
    //***************************highest score function******************************************
    
    void highestScore (int exam[])
         {								//local function definitions are illegal???
    
                  for (int x=0; x<5; x++)
    
              {
    
                   if (exam[x] > highestScore)
    
                   highestScore = exam[x];
    
              }
    
         }	
    			
    cout <<"\n" << highestScore <<" is the highest test scores. "<<"\n";
    			
    
    
    return;
    
    }

  2. #2
    Registered User Elhaz's Avatar
    Join Date
    Sep 2004
    Posts
    32
    Hi dAzed,

    You missed the closing curly bracket } at the end of void averageScore(int num[]) - it thinks you're trying to declare void highestScore (int exam[]) in void averageScore(int num[]).

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    66
    cout <<"\n" << tot <<" is the total of the test scores. "<<"\n";
    cout <<"\n" << avg <<" is the average test score. "<<"\n";
    there´s a } sign missing, also, in the last funcyion I believe you close a bracket } you never opened

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    >>void main()

    Bad! Use:

    int main()

    Good!
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    I correct some little error, now it's pass compiling:

    Code:
     #include <iostream>
        using namespace std;
        
        //**********************************************Func  tion prototypes
        void enterScore(int score&#091;&#093;);   
        void averageScore(int score&#091;&#093;);
        void highestScore(int score&#091;&#093;);
         
        //**********************************************Func  tion main
        int main()
        {
          int score&#091;5&#093;;    
            enterScore(score);
            averageScore(score);
            highestScore(score);
            
            system("pause");
            return 0;    
        }
        
        //*************************enter score function******************************************  **
        
        void enterScore(int grade&#091;&#093;)
          {
          for (int x = 0; x<5; x++)
        {
          cout << "\nEnter score #"<<" ";
          cin >> grade&#091;x&#093;;
            
          }
        }
        
        //**************************average score function******************************************  *
        void averageScore(int num&#091;&#093;)
        {
          int tot = 0;
          int avg = 0;
        
          for (int x=0; x<5; x++)     
          
            tot+=num&#091;x&#093;;
        
            avg = tot/5;
        
          cout <<"\n" << tot <<" is the total of the test scores. "<<"\n";
          cout <<"\n" << avg <<" is the average test score. "<<"\n";
        }     // add }
        
        //***************************highest score function******************************************  
        
        void highestScore (int exam&#091;&#093;)
        {
             int highestScore = 0;
             //local function definitions are illegal???
             for (int x=0; x<5; x++)   
             {   if (exam&#091;x&#093; > highestScore)
                    highestScore = exam&#091;x&#093;;
              }       
             cout << "\n" << highestScore 
                  << " is the highest test scores. " << "\n";   
        
            return;    
        }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble moving lines up in 2D array
    By powell5487 in forum C Programming
    Replies: 5
    Last Post: 03-03-2009, 11:54 AM
  2. Array trouble
    By Cpro in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2006, 12:55 PM
  3. trouble creating an array
    By s_ny33 in forum C++ Programming
    Replies: 7
    Last Post: 04-25-2005, 11:18 AM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21