Here's the code. I'm trying to read data from a text file and put it into an array... I'm trying to do this using a function.... can anyone please help..... it's not running. There's an error somewhere....

int main()
{

 
    

    float readFloat(std::ifstream& readFile)
    {
       float holdData = 0;
       while(holdData != (-(holdData)))//error checking 
       {
       readFile >> holdData;
       return holdData;
       }
    }

    
    
    float rainfallData[12] = {0.0F};
    int i; // loop counter
    ifstream myfile ("rainfall.txt");
    if( myfile.is_open() )
    {
        i = 0;
        while( i < 12 && myfile >> holdData[i] )
            i++;
    }
    
    
    
    
    
    void readFloatArray(std::ifstream& readFile, float *Array, const float Size)
    {
        float index = 0;
        //while index is not equal to Size AND !readFile.fail 
        //  Array[index] equals readInt(readFile);
        // ++index;
}

 





}

Function definitions belong outside of main(). One style is to put prototypes before main and definitions afterwards, or you can just put the definition before without needing a prototype

void myfunc(int, int);

int main()
{

}

void myfunc(int param1,int param2)
{


}

I'll try that.... thanks a lot

Hi.... it still won't run... I've edited it... pls help again....
Here's the code

/**This program reads monthly rainfall data from a file called rainfall.txt which
contains 12 amounts of rainfall, performs some arithmetic processes on the data
and writes the processed data to a file called results.txt. **/

#include <iostream>
#include <fstream>
#include <string>
using namespace std;


float readFloat(std::ifstream& readFile)
    {
       float holdData = 0;
       while(holdData != (-(holdData)))//error checking 
       {
       readFile >> holdData;
       return holdData;
       }
    }

void readFloatArray(std::ifstream& readFile, float *Array, const float Size)
    {
        float index = 0;
        //while index is not equal to Size AND !readFile.fail 
        //  Array[index] equals readInt(readFile);
        // ++index;
    }
     

int main()
{
    float holdData;
 
    

    

    
    
    float rainfallData[12] = {0.0F};
    float i; // loop counter
    ifstream myfile ("rainfall.txt");
    if( myfile.is_open() )
    {
        float i = 0;
        while(i < 12 && myfile >> holdData[i] )
            i++;
    }
    
    
}

You have to pick one of your threads, don't just keep adding to both. What's not working about it?

You have to pick one of your threads, don't just keep adding to both. What's not working about it?

sorry.... was a mistake... reply here... or there... anywhere is fine.....

The program is not running.... telling me there's an error.... it says "invalid types `float[float]' for array subscript".... don't know what it means

floats are not an array subscript, ints are. You have it right there in the comments that it's a counter so it's not going to have decimal digits.
We won't be able to do this inch by inch, it looks like you made the first function and then tested it, no? Is that what you are trying to accomplish with this one?

Thanks a lot for your help... I'll figure something out... I'm like sleeping... appreciate your help though

You have to pick one of your threads, don't just keep adding to both.

sorry.... was a mistake... reply here... or there... anywhere is fine.....

No it isn't. "Anywhere is fine" doesn't solve the problem.

Other thread closed. Problem now solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.