dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Really need help with my Array HW

Threaded View

  1. #1
    Join Date
    Dec 2018
    Posts
    1

    Really need help with my Array HW

    So I need to write a c++ program where:


    1)Read a sequence of integers from a file into an array
    2) Pass that array of integers to a function which will compute and return the average (as a double).
    3) Display the average returned from the function


    I feel like I am overthinking it but here is what I have so far:

    Code:
    #include<iostream>
    #include<fstream>
    #include<string>
    using namespace std;
    
    int main()
    {
        int n = 0; //n is the number of the integers in the file ==> 12
        int num;
        int arr[100];
    
        ifstream File;
        File.open("numbers.txt");
        while(!File.eof())
        {
            File >> arr[n];
            n++;
        }
    
        File.close();
    
        for(int i=0;i<12;n++)
        {
            cout << arr[i] << " ";
        }
    
        cout << "done\n";
        return 0;
    }
    Last edited by VictorN; December 4th, 2018 at 03:27 PM. Reason: add CODE tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)