Thread: Stream function question

  1. #1
    Registered User
    Join Date
    Feb 2003

    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...

    #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"input.dat");
    if (
       cout << "Error opening file input.dat\n";
     read_file(fin, sum, count);
    void read_file(ifstream& fin, double& sum, double& count)
      int next;
      fin >> next;
    while (!fin.eof())
       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
    void main()
    should be
    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, 08:28 AM
  2. CreateThread() function question
    By chiefmonkey in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2009, 07:52 AM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  4. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03: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