Declaration (prototype) for void function

This is a discussion on Declaration (prototype) for void function within the C++ Programming forums, part of the General Programming Boards category; 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> ...

  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
    32,821
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    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, 01:27 PM
  2. Prototype Declaration
    By rrahulvverma in forum C Programming
    Replies: 6
    Last Post: 10-13-2010, 01:18 PM
  3. Replies: 3
    Last Post: 07-15-2010, 10: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, 12:03 PM

Tags for this Thread


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