C++ arrays question

This is a discussion on C++ arrays question within the C++ Programming forums, part of the General Programming Boards category; Hi..I am writing a program to read a file containing student names and scores for 3 tests and output the ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    Smile C++ arrays question

    Hi..I am writing a program to read a file containing student names and scores for 3 tests and output the highest in each test. What am I doing wrong? Thanks.(There are 6 students in the class)..

    Code:
    //Sample Program 12- A non-interactive program to calculate student grades.
    //**************************************************************************************
    #include<iostream>
    #include<iomanip>
    #include<fstream>
    #include<string>
    using namespace std;
    
    const int SIZE=6;
    int GetHighValue(int array[]);
    
    int main()
    {
    	int exam1Array[SIZE];
    	int exam2Array[SIZE];
    	int exam3Array[SIZE];
    	int i=0;
    	string name;
        ifstream inFile;
    
    	inFile.open("grades.dat");
    		if(!inFile)
    		{
    			cout<<"Unable to open input file, program abnormally ended";
    			return 1;
    		}
            for(i=0; i<SIZE; i++)
    		{
             
             inFile>>name>>exam1Array[i]>>exam2Array[i]>>exam3Array[i];
    		 
    		}
    		 
    			
            GetHighValue(exam1Array[i]);
    		cout<<"The highest for exam 1 is"<<GetHighValue(exam1Array[i])<<endl;
    	    GetHighValue(exam2Array[i]);
    		cout<<"The highest for exam 2 is"<<GetHighValue(exam2Array[i])<<endl;
    	    GetHighValue(exam3Array[i]);
    		cout<<"The highest for exam 3 is"<<GetHighValue(exam3Array[i])<<endl;
    		 
    		
    		 
             
    		 
    		 return 0;
    }
    
    
    
        int GetHighValue(/*in*/ int array[])
    			{
    				 int highScore=0;
    				 int i=0;
    
    				 for(i=0; i<SIZE; i++)
    				 {
    					 if(array[i]>highScore)
    						 highScore=array[i];
    				 }
    
    				 return highScore;
    			}
    Last edited by Dave_Sinkula; 08-01-2006 at 08:39 PM. Reason: Added [code][/code] tags -- learn to use them yourself.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    what the error and where it happens
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    errors

    One of the errors is that the first parameter int cannot be converted to int[]

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
       GetHighValue(exam1Array);
       cout<<"The highest for exam 1 is"<<GetHighValue(exam1Array)<<endl;
       GetHighValue(exam2Array);
       cout<<"The highest for exam 2 is"<<GetHighValue(exam2Array)<<endl;
       GetHighValue(exam3Array);
       cout<<"The highest for exam 3 is"<<GetHighValue(exam3Array)<<endl;
    Note the missing [i]. Perhaps post the input file for further scrutiny.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    Thanks!!

    That part of the program works excellently now. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about arrays.
    By Kelvie in forum C++ Programming
    Replies: 3
    Last Post: 09-17-2007, 06:32 AM
  2. A question concerning character arrays
    By ellipses in forum C Programming
    Replies: 3
    Last Post: 03-08-2005, 08:24 PM
  3. Replies: 6
    Last Post: 04-26-2004, 11:02 PM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 01:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 03:40 PM

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