Stream function question

This is a discussion on Stream function question within the C++ Programming forums, part of the General Programming Boards category; Can anyone tell me why my fuction does not return anything when the program is run? It compiles correctly but ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Lightbulb Stream function question

    Can anyone tell me why my fuction does not return anything when the program is run? It compiles correctly but it wont output anything...

    Code:
    #include <iostream.h> 	// for output to screen
    #include <fstream.h>  	// for file I/O
    #include <stdlib.h>	// for exit function
    
    void read_file(ifstream& fin, double& sum, double& count);
    
    void main()
    {
    double sum=0;   // accumulates sum of values in file
    double count=0; // counts number of values read
    ifstream fin; 	// input file stream
    
    fin.open("input.dat");
    if (fin.fail())
    {
       cout << "Error opening file input.dat\n";
       exit(1);
    }
    
     read_file(fin, sum, count);
    }
    
    void read_file(ifstream& fin, double& sum, double& count)
    {
      int next;
    
      fin >> next;
    while (!fin.eof())
    {
        count++;
       sum += next;
       fin >> next;
    }
    cout << "Number of values read: " << count << endl;
    cout << "Sum of values read: " << sum << endl;
    cout << "Average value: " << sum/count << endl;
    
    }

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Code:
    void main()
    should be
    Code:
    int main()
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 09:28 AM
  2. CreateThread() function question
    By chiefmonkey in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2009, 08:52 AM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  4. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  5. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM

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