0

i keep getting an error when i try to pass the array through function. Help?

#include <iostream>
#include <fstream>
#include <string> 
#include <iomanip>

using namespace std;

void input(double carSpeed[6][7]);

int main (void)
{   
    double carSpeed[6][7];

    input(carSpeed[][]);


    return 0;
}

void input(double carSpeed[][7])
{
    ifstream FileName;
    FileName.open("noise.txt"); 
    for(int x=0; x<6; x++)
    {
        FileName >> carSpeed[x][0];
        for(int y = 1; y < 8 ; y++)
        {
            FileName >> carSpeed[x][y];
        }
    }
    FileName.close();

    return;
}

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Nandomo
0

Always believe that it's better to make the COLS a const.

const int COLS = 7;

In the prototype and function header just do as follows.

void input(double carSpeed[][COLS]);

// ...

void input(double carSpeed[][COLS])
{
ifstream FileName;
FileName.open("noise.txt"); 
for(int x=0; x<6; x++)
{
FileName >> carSpeed[x][0];
for(int y = 1; y < 8 ; y++)
{
FileName >> carSpeed[x][y];
}
}
FileName.close();

return;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.