I am going to be straight forward here, this is a hw assignment but I do not want the whole assignment answered. I can figure out the rest pretty easily I'm just stuck on one part that is getting me frustrated. I am just not seeing what I'm doing wrong.
The main program will call a series of functions to process a set of data. One function will read data into an array. A second function will print the values stored in an array in a neat format. Another function will find the average of the values stored in an array. A fourth function will construct a new array from an existing array.
Here are the details on the main program:
1. The main program will read in a parameter value (which the main program will call size). Note that the main program reads this value, not one of the functions.
The main program will call a function readdata to read size items into an array (which the main program will call first or something else of your choice).
A. The function readdata will read data into an array. The function will receive two parameters: an integer n, and an array of doubles called numbers. At the beginning, n will have a value, and the array will be empty. The function will read n lines of data. Each line of data should contain a number of type double (so it might have decimal places). The values stored in this array will be sent back to the main program, to be used throughout the program.
This is what I have so far. The part that is in bold is what is confusing me. I think I wrote the readdata function correct but its the declaration of size and first that is giving me a hard time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream>
#include <fstream>
using namespace std;
void readdata(int &, double[]);
int main()
{
int size;
double first[50];
ifstream example;
example.open ("example.txt");
example >> size
readdata(size, first);
return 0;
}
void readdata(int &n, double numbers[])
{
for(int i=0;i <= n; i++){
example >> numbers[i];
}
return;
}
|
I get error In function `int main()':|
error: cannot convert `double*' to `double' for argument `2' to `void readdata(int, double)'|