Thread: Declaration (prototype) for void function

  1. #1
    Registered User meb193's Avatar
    Join Date
    Oct 2012
    Posts
    2

    Declaration (prototype) for void function

    I'm having trouble understanding what I'm supposed to do and how to do it, please help


    Code:
    #include<iostream>
    #include<fstream>
    #include<string>
    using namespace std;
    
    
    /*  TODO:   Write the declaration (prototype) for void function GetLeast that
                takes an ifstream parameter called infile as an input parameter
                that is changed, and that has an int parameter called lowest
                that returns a value.
    
    
                Document the data flow for the parameters with appropriate comments.
    */
    
    
    //------------------------------------------------------------------------------
    
    
    int main()
    {
        int smallestValue = INT_MAX;        // Initialize smallest to maximum range
        ifstream dataFile;                                  // File input stream
        const string filename = "data.txt";                 // Input file name
    
    
        cout << "Opening file...";
    
    
        dataFile.open(filename.c_str());                    // Open file
    
    
        if(dataFile)                                        // File opened OK?
        {
            cout << "file opened." << endl
                 << "Begin searching for lowest value...";
    
    
            /*  TODO:   Call function GetLeast, passing the ifstream variable
                        and int variable as arguments.
            */
            
    
    
    
    
    
    
            cout << "done.\n" << endl;                      // Print result
    
    
            cout << "The lowest value found was "
                 << smallestValue << endl;
        }
        else                                                // Problem opening file
        {
            cout << "could not find or open file: " << filename
                 << endl;
        }
    
    
        dataFile.close();
    
    
        cout << "\nEnd Program.\n"
             << endl;
    
    
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I suppose we can start with this, and see what you can come up with for the implementation and explanation.
    Code:
    void getLeast ( ifstream &dataFile, int &smallestValue );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    The following tutorial might help you. Take a look at it and see what you can do. Don't worry if you can't get it to copmile or work, just have a go and post your best effort.
    Functions in C and C++ - Cprogramming.com
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-11-2012, 12:27 PM
  2. Prototype Declaration
    By rrahulvverma in forum C Programming
    Replies: 6
    Last Post: 10-13-2010, 12:18 PM
  3. Replies: 3
    Last Post: 07-15-2010, 09:14 AM
  4. Replies: 2
    Last Post: 11-27-2007, 01:01 AM
  5. Impact of void on prototype
    By kolistivra in forum C Programming
    Replies: 3
    Last Post: 08-23-2006, 11:03 AM

Tags for this Thread