It says : "redefinition of formal parameter 'size'"
and: "redefinition of formal parameter 'menu'"
I tried but still cannot figure out.
and: "redefinition of formal parameter 'menu'"
I tried but still cannot figure out.
#include <iostream> #include <fstream> #include <iomanip> #include <string> #include <vector> using namespace std; // Function of max void loadData ( int *arr, int &size) { int size=0; while(size != 0) { string name; cout <<"Enter data file name:" << endl; getline(cin, name); ifstream inputFile; inputFile.open(name.c_str(), ios_base::in); // Open file if (inputFile.is_open()) { cout <<"Finished loading data" << endl; int count; while (inputFile >> count) // Count the numbers in the file size++; inputFile.close(); //Create a dynamic array to hold the values vector<int> arr; //Create an input file stream ifstream inputFile(name.c_str(),ios::in); int number; //Variable to hold each number as it is read //Read number using the extraction (>>) operator while (inputFile >> number) { //Add the number to the end of the array arr.push_back(number); } //Close the file stream inputFile.close(); } else { cout <<"Cannot read the file!"<< endl; } } } // Function of sorting data void sort ( int a[], int &size ) { bool swapped; do { swapped = false; for ( int i = 1; i < size; i++) { if ( a[i - 1] > a [i] ) { int temp = a[i-1]; a[i-1] = a[i]; a[i] = temp; swapped = true; } } size = size -1; }while ( swapped ); } // Function of showwing data void showData ( int a[], int &size) { cout << "Data:" << endl; for ( int i = 1; i < size; i++) cout << a[i] <<" | "<< endl; } int displayMenu(int &menu) { cout <<"---- Main Menu ----\n"<< endl; cout <<"1. Load data from file\n"<< endl; cout <<"2. Sort data\n"<< endl; cout <<"3. Display data\n"<< endl; cout <<"4. Exit\n"<< endl; cout <<"Your menu choice: "<< endl; int menu = 0; cin >> menu; while ((menu < 1) && (menu >4)) { cout <<"Error! "<< endl; cout <<"Your menu choice: "<< endl; cin >> menu; } } int main() { int* iarr; int isize; int choice; while (choice = 4) { displayMenu(choice); if (choice = 1) loadData (iarr, isize); else if (choice = 2) sort (iarr, isize); else if (choice = 3) showData (iarr, isize); } return 0; }