Cannot Call Another Function with Function

So basically I am trying to finish this program where I have to submit a phone database.

Overview:

What is this assignment about?
You have recently started a small business that sells smart phones. In the first version of this assignment, you used arrays in C++ to implement some very basic functionality such as: add, update, display, print.


In the second part of this assignment, you will:
Add a menu item allowing the user to delete a phone.
Allow lookup queries by different criteria.
Change the productID to be a 4 character C-string. The first 2 should be alphabetical characters (A-Z) and the last 2 should be digits (0-9). You will use C-string functions to compare two productID's. The array of productID's will be a 2D array (viewed as a 1d array of C-strings).
Use dynamic memory allocation to allocate the arrays, and then double the size of the array if it gets filled. (Note: You can use dynamic memory allocation for only one array and you will still get full credit. E.C. to use for all arrays.)
Add another array of type C++ string to store the names of the phones.
Necessary Functions

Here are some of the new functions that should be written:
delete_phone: Given a product number, remove this phone from the database. This function should call find_phone to locate the location of the phone in the array. It should then remove the phone from the array if the quantity on hand is 0. This can be implemented in one of several ways (some choices are: (a)you can shift over everything else in the array (b) you can place a special value in the productnum array at that location indicating that it is empty.)

Some things to think about: you most likely will have to maintain the number of phones in the database. Be sure to update this when both adding and deleting. If you use option b, you will have to change your add_phone function to find an empty entry in the array.

query_database: This function should have a submenu allowing the user to query the database by product number, name, or price. If the user chooses product number or name, you will call find_phone and then display_phone.If the user chooses price, allow them to enter a range of prices.

grow_array: This function will enlarge the size of the array using dynamic memory allocation. (Hint: we wrote a similar function in class.)
Error Checking

Some new things to check for: if the user tries to delete a phone that is not in your database, or if the user enters an invalid product number.


However, when I try to compile it, it gives me an error about conversion. In one of my functions it calls for a another function.

|263|error: invalid conversion from 'int' to 'int*' [-fpermissive]|
|14|note:   initializing argument 5 of 'void printArray(char (*)[5], std::__cxx11::string*, double*, int*, int*)'|


Here is my some of my code below (the entire program is too long to put onto this):

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
int findID (char [][5], string, int&);
double buyPhone(int, double, int&);
double updatePrice(double[], int);
void printArray(char [][5], string[], double[], int[], int*);
void query_database(char [][5], string[], double [], int[], int);
void exit();

void printArray(char arr[][5], string n, double b[], int c[], int *w)

{

    for ( int i = 0; i <*w; i++)
        {
        cout<< "Name: " << n[i] << ' '<<endl;
        cout<<"ProductID: "<< arr[i] << ' '<<endl;
        cout <<"Price: " <<"$"<<b[i]<<' '<<endl;
        cout <<"Amount: "<<c[i]<<' '<<endl;
        cout<<endl<<endl;
    }
    cout << endl;

}

void query_database(char ar[][5], string gt[], double p[], int c[], int amt)
    {
        string q;
        string name;
        string id;
        string price;
       cout<<"Do you want to search by name, product ID, or price?"<<endl;
       cin >> q;

       if(q == "name")
       {
           cout<<"Please enter the name you want to look for?"<<endl;
           string name;
           for(int i=0 ; i<amt; i++)
           {
               if(name == gt[i])
             printArray (ar, gt, p, c, amt);
              else
                    cout<<"Not found."<<endl;
           }

       }
    }
Last edited on
argument 5 of printArray
void printArray(char arr[][5], string n, double b[], int c[], int *w)
is the w, which is a int*, a pointer.

On line you call printArray and give amt as fifth parameter. The amt is an int, an integer.

cannot conversion 'int' into 'int*'

@keskiverto Well I tried changing it to a regular int by removing all the "*" from the variables. However, it still gave me this:

undefined reference to `printArray(char (*) [5], std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, double*, int*, int)'|
undefined reference to `printArray(char (*) [5], std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, double*, int*, int)'|
||error: ld returned 1 exit status|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
Last edited on
@keskiverto - oh wait I see what you mean now sorry. So after I put in the proper pointers:
After fixing my code:
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
27
28
29
30
31
32
33
34
35
36
37
38
void printArray(char arr[][5], string n, double b[], int c[], int *w)

{

    for ( int i = 0; i <*w; i++)
        {
        cout<< "Name: " << n[i] << ' '<<endl;
        cout<<"ProductID: "<< arr[i] << ' '<<endl;
        cout <<"Price: " <<"$"<<b[i]<<' '<<endl;
        cout <<"Amount: "<<c[i]<<' '<<endl;
        cout<<endl<<endl;
    }
    cout << endl;

}
    void query_database(char ar[][5], string gt[], double p[], int c[], int *amt)
    {
        string q;
        string name;
        string id;
        string price;
       cout<<"Do you want to search by name, product ID, or price?"<<endl;
       cin >> q;

       if(q == "name")
       {
           cout<<"Please enter the name you want to look for?"<<endl;
           string name;
           for(int i=0 ; i<*amt; i++)
           {
               if(name == gt[i])
             printArray (ar, gt, p, c, amt);
              else
                    cout<<"Not found."<<endl;
           }

       }
    }


However, it gives me this output:

undefined reference to `printArray(char (*) [5], std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, double*, int*, int*)'|
undefined reference to `printArray(char (*) [5], std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, double*, int*, int*)'|
||error: ld returned 1 exit status|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

Topic archived. No new replies allowed.