I'm currently writing a program that reads information from an already created file, and displays the information in an array. I created one function that takes the data from the file and places it in the array. I created a second function to output the array. However, when I place my function to output the the array within my int main(), I get the following error:
error C2664: 'display_array' : cannot convert parameter 1 from 'int' to 'int []'
This might be something simple, but I'm new with arrays. Here is my code:Code:#include<iostream.h> #include<iomanip.h> #include<fstream.h> void program_description(); void get_info_from_file( ifstream &i_file, int arr[], int &no_items ); void display_array( int arr[], int no_items ); const int max_list = 50; int main() { //Variable Declarations int number; int no_values; int array[max_list]; ifstream in_file; no_values = 0; program_description(); display_array( array[max_list], no_values ); return 0; } //Function Definitions void program_description() /*======================================================================================= This function outputs a description of the program to the user. INPUT: None OUTPUT: None =======================================================================================*/ { cout << "Greetings! This program is designed to take the "; cout << "data\ncurrently stored in another file and display it to you. It will then "; cout << "sort the data, number it, and calculate the sum, range, mean, and median. "; cout << "From there a\nhistogram of the data is displayed.\n\n"; } void get_info_from_file( ifstream &i_file, int arr[], int &no_items ) /*======================================================================================= This function opens the input stream, gets the data from the file one item at a time, and stores each item in an array element. It also counts the number of items in the file. Lastly, the input stream is closed. INPUT: A parameter of type ifstream, an array of integers, an integer which represents the number of items in the file. OUTPUT: This function returns nothing. =======================================================================================*/ { int data; no_items = 0; i_file.open("stat_data"); i_file >> data; arr[no_items] = data; no_items ++; while ( ! i_file.eof() ); { i_file >> data; arr[no_items] = data; no_items ++; } } void display_array( int arr[], int no_items ) /*======================================================================================= The function traverses the array of integers, outputting each element in the array. INPUT: an array of integers, an integer which represents the number of items in the file. OUTPUT: This function returns nothing. =======================================================================================*/ { int no_scores; no_scores = 0; for ( int i = 0; i < no_scores; i++ ) { cout << arr[i] << " "; } }



LinkBack URL
About LinkBacks


