Thread: Pointers with pointers please!!!!!!!!!

  1. #1
    Registered User
    Join Date
    Apr 2005

    Pointers with pointers please!!!!!!!!!

    //This still has 2 errors, asking for return values from
    //calcaverage and from findlowest.  Can anyone help me?
    //This program asks the user to pick the number of test
    //scores they wish to average, drops the lowest(returning
    //'lowestscore'and showing it) and then it calculates the
    //average minus the lowestscore).  Could someone please
    //take a look and let me know how to fix it.  THANKS !!!
    /* You don't necessarily need to pass anything back to main.
       It is probably better to calculate the lowest value first
       and then call the function calculate average.
       So no values are returned to main
    #include <iostream>
    //The inside of the brackets tells you
    //how many variables are being passed and
    //if they are integers floats or arrays.
    //Don't forget the ';'
    int calcaverage(float [],int,float);
    int findlowest(float [],int );
    using namespace std;
    int main()
        float Scores[81];
    	int HowMany;
    	cout<<"How many scores do you wish to input?";
    	cout<<"Enter your "<<HowMany<<" scores.\n";
    	for (int i=0; i<HowMany; i++)
         //Calls the function 'findlowest' passing the array
         //'Scores' into it and the variable 'howmany'
         //When calling functions you don't need to declare
         //if they are integers or if they are arrays or their size
         //Don't forget the ';' at the end of the bracket
    int stop;
    return 0;
    //This function finds the lowest score and returns it.
    //Here you must declare what type they are
    //For an array such as Scores you need to write float Scores[]
    //The square brackets are needed/
    //Note here you don't need the ';' at the end of the bracket
    int findlowest(float Scores[],int HowMany)
    	float lowest=10000;
    	for(int a=0; a<HowMany; a++)
        cout<<"Your lowest score was "<<lowest<<endl;
        //call function 'calaverage' passing the array
        //'Scores'into it, 'howmany' and 'lowest'
        //note it passes int three variables to 'calcaverage'
        //Therefore the function declaration should
        //have three variables as shown below          
    int calcaverage(float Scores[],int HowMany,float lowest)
    {   float average;
        float total=0;
        for (int a=0; a<HowMany; a++)
            if (Scores[a]!= lowest)//ignore the lowest score
        average=total/(HowMany-1);//-1 to ignore the lowest score
                                  //therefore the array has shrunk by one.
        cout<<"The average was "<<average<<endl;

  2. #2
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    //This still has 2 errors, asking for return values from
    //calcaverage and from findlowest. Can anyone help me?
    the functions are ints. They must return values. Return 0 if you want to end the thing successfully but don't care to reference to the return value; or use void functions
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Manassas, VA USA
    Your calcaverage() and findlowest() functions are prototyped to resolve to returning an 'int'; however, neither function contains a single return statement. This is ok, but only if you prototype your functions to be 'void'.


    function prototypes:
    void calcaverage(float [],int,float);
    void findlowest(float [],int );
    'void' lets your compiler know that the functions will not have any return value. Also, be sure to reflect the same changes in your function definitions as well.
    Last edited by The Brain; 04-12-2005 at 09:33 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM