Thread: determining what should be placed in function's parameter

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    determining what should be placed in function's parameter

    Code:
    #include <iostream>
    #include <limits.h>
    using namespace std;
    
    int getValues(void);
    int findLowest(int, int, int, int, int);
    float calcAverage(int, int);
    
    int main ()
    
    {
    	int gV;
    	int fL;
    
    	float calc;
    
    	gV = getValues();
    	
    	fL = findLowest(gV);
    
    	calc = calcAverage(gV, fL);
    	
    
    	cout << "The average of the four highest scores "
    		 << "is  " << calc << endl;
    
    	return 0;
    	
    }
    
    int getValues (void)
    {
    	int score1;
    	int score2;
    	int score3;
    	int score4;
    	int score5;
    
    	cout << "Enter five test scores" << endl;
    
    	cin >> score1;
    	cin >> score2;
    	cin >> score3;
    	cin >> score4;
    	cin >> score5;
    
    	findLowest(score1, 
    			   score2, 
    			   score3, 
    			   score4, 
    			   score5);
    
    	return score1 && score2 && score3 && score4 && score5;
    
    }
    
    int findLowest(int score1, 
    			   int score2, 
    			   int score3, 
    			   int score4, 
    			   int score5)
    
    {
    	int lowest = INT_MAX;
    
    	for (int i = 0; i < 5; i++)
    	{
    		if(score1 < lowest)
    			lowest = score1;
    		
    		if(score2 < lowest)
    			lowest = score2;
    		
    		if(score3 < lowest)
    			lowest = score3;
    		
    		if(score4 < lowest)
    			lowest = score4;
    		
    		if(score4 < lowest)
    			lowest = score5;
    	}
    
    		return lowest;
    
    }
    
    float calcAverage(int scores, int lowest_score)
    
    {
    	return float (scores - lowest_score) / 4;
    }
    Help me out, please: I'm not sure what I should enter in the parameters findLowest(); and calc = calcAverage();

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you should do the getValues fxn stuff in main; otherwise if you want to use another fxn, think about declaring ints in main, and passing them as reference parameters to getValues.

    or just call findLowest from getValues, return the lowest number to getValues, and then return that to main.

    you can't call findLowest in main like you did, because it takes 5 parameters, not one. and you can't return the scores like you did in getValues.

    edit: also, you shouldn't need the for loop in findLowest. also, in calcAverage, you can pass it correctly, but if you want the sum of the scores, then you would have to
    Code:
    return score1 + score2 + //etc.
    not the way you did it. you may want to think about it a bit more
    Last edited by alpha; 03-23-2003 at 05:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 07:05 PM
  3. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  4. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  5. Inline functions and inheritance
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2004, 06:46 PM