Thread: Help!! Compiles w/o errors, but till doesn't execute right!!! HELP

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    5

    Help!! Compiles w/o errors, but till doesn't execute right!!! HELP

    Ok, i was told to make a program which reads number grades from an input file, saves them to an array, finds out the largest grade, the number of grades, then gets the grades individually and finds the curved grade and prints them to an output file.

    My problem is that i do all this, it compiles with 0 errors but an error still occurs when i try to run it, also, in the output file, only one of the curved grades comes out, here is the program so far, PLEASE HELP ME OUT!!!
    Code:
    #include <iomanip>
    #include <iostream>
    #include <fstream>
    
    using  namespace  std;
    const int max=20;
    
    void  getthem ( int [], int&, ifstream ) ;                            
    void  printthem ( const int [], int, int, ofstream) ;
    float curvegrade(int , int);
    float getmax ( const int[], int, int&);
    
    int main ()
    {
    	ifstream infile;
    	ofstream outfile;
    	
    	
    	int numgrades;
    	int grades[max];
    	int maxg;
    	
    	
    	//***********************************Open files and check for errors**********************************
    	infile.open ("indata7.txt");
    	
    	if  (!infile)
    	{
    		cout << " CAN’T OPEN INPUT FILE ! " << endl;
    		return 1;
    	}
    	
    	outfile.open ("outdata7.txt");
    	if  (!outfile)
    	{
    		cout << " CAN’T OPEN INPUT FILE ! " << endl;
    		return 1;
    	}
    	
    	//***********************************Call functions**************************************************
    	
    	
    	getthem(grades, numgrades, infile);
    	
    	getmax(grades, numgrades, maxg);
    	
    	printthem(grades, maxg, numgrades, outfile) ;
    	
    	
    	return 0;
    	
    }
    
    void getthem (int  grades[], int& num, ifstream infile) 
    
    {
    	int m;
    	
    	num = 0; 
    	m=0;
    	
    	while (infile)      
    	{
    		infile >> grades[m];
    		num = num + 1 ;
    		m++;
    	}
    	
    }
    
    float getmax (const int grades[], int number, int& maxgrade)
    {
    	int m;
    	
    	maxgrade = grades[0];
    	
    	for (m = 1; m < number; m++)
    	{
    		if (grades[m] > maxgrade)
    			
    			maxgrade = grades[m];
    		
    	}
    	
    	return maxgrade;
    	
    }
    
    void printthem (const int  grades[], int  maxgd, int number, ofstream outfile) 
    
    {
    	int m;
    	outfile<<"Student		Absolute	  Curved"<<endl<<"Number	           Grade           Grade"<<endl<<"---------    	-----------     -----------"<<endl;
    	
    	for (m =1; m < number; m++)
    	{
    		outfile<<m<<setw(20)<<grades[m-1]<<setw(14)<<curvegrade(grades[m-1], maxgd)<<endl;
    	}
    	
    }
    
    
    float curvegrade(int absgrade, int maxgrade)
    {
    	int curve;								
    	
    	static_cast<int>(static_cast<float>(curve = (absgrade/maxgrade * 100) + .5) ) ;
    	
    	return curve;
    	
    }
    Input file is indata7.txt
    60
    75
    69
    85
    92
    88
    84
    73
    93
    54

    Thanks, and please help asap!!!

    and i'm using Visual C++ 6.0
    Last edited by rdt253; 04-26-2004 at 05:29 PM.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    If you want more help you need to do two things my friend: 1. use [(CODE] tags to format your code...if you don't know how, read the threads on the top of the forum, and 2. tell us what compiler you are using.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    5
    is that what you meant by compiler axon?? hope that helps u help me

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    I don't have too much time to go over the whole prog, but a certain thing pops up: why is the function getmax of type float? you really don't need that since you are reading in the scores into an int array, not a float array....

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    5
    yeah, your right, thanks for the heads up, program runs smoothly now, you've been alot of help
    RDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  3. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM
  4. Simple Program wont execute after compiles w. no errors
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 02-03-2002, 04:24 PM