No instance of overloaded function and cannot convert argument 2 from int * to int

Hi, i'm currently in my 2nd computer science class in college. I have been writing a program that is supposed to give a menu for the user to choose an option 1-4 then add, update, or find info based on their choice. I have most the code written, and now I am left with 2 errors: Error 1 error C2664: 'void addcust(Customer [],int)' : cannot convert argument 2 from 'int *' to 'int' and 2 IntelliSense: no instance of overloaded function "addcust" matches the argument list argument types are: (Customer [30], int *)

Heres 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  #include <iostream>
#include <string>
#include <iomanip>

using namespace std;



const int MAXCUST = 30;  // Constant value for the maximum number of customers possible

struct Customer
{
	int id;    	// id
	string name;    // Name
	string zip;     // ZIP code
	double balance; // Account balance
	string lastPay; // Date of last payment
};
int menu();  // Function prototype for menu
void addcust(Customer CD[MAXCUST], int NumCust);  // Function prototype for addcust (Add customer)
void updatecust(Customer CD[MAXCUST], int NumCust); // Function prototype updatecust (Update customer)
void displaycust(Customer CD[MAXCUST], int NumCust); // Function prototype for displaycust(Display customer)
int findcust(Customer CD[MAXCUST], int id, int NumCust); // Function prototype findcust(Find customer)


int  main(){
	int NumCust;   // Declares NumCust, the number of customers in the array
	int choice;  // Declares choice, the literal choice for the menu, 1-4
	Customer CD[MAXCUST];  // Declares the array of structs at a size of MAXCUST which is = to 30
	menu(); // Call for menu, which displays the menu
	while (choice != 4){  // While loop to run the menu program untill 4 is returned


		if (choice == 1){  // Option for choice 1
			if (NumCust < MAXCUST){  // Validation to make sure the array isnt full already

				addcust(CD, &NumCust);  // call for addcust

			}
			}
			else if (choice == 2){
				updatecust(CD, NumCust);  // call for update cust, which is called when 2 is chosen and thus returned by the menu function
			}
			else if (choice == 3){  
				displaycust(CD, NumCust); // call for displaycust, which is called when 3 is chosen and thus returned by the menu function

			}
		}
	return 0;
	}



int menu(){  // Function for menu

	int NumCust;  // Declares NumCust
	int choice;  // Declares choice

	cout << "1. Enter new account information\n";
	cout << "2. Change account information\n";
	cout << "3. Display all account information\n";
	cout << "4. Exit the program\n\n";
	// The options displayed for the user to read
	cout << "Enter your choice: ";
	cin >> choice;   // Allows for the user to input their choice
	if (choice >= 1 && choice <= 4)  // Validates that the choice is between 1 and 4

		return choice;  // Returns the choice; a number between 1 and 4
	else
	{
		cout << "Invalid choice, enter again";  // Displays if the choice is outside of the valid choices
	}

}

	void addcust(Customer CD[MAXCUST], int &NumCust){  // Function for addcust

		int id;
		string name;  // Declares id, name, zip, balance, and last pay
		string zip;
		double balance;
		string lastPay;

		cout << "Please enter ID number";  // Asks for ID number
		cin >> CD[NumCust].id;   // Allows user to input id number which goes into the specific customer's struct
		
		cout << "Please enter name"; // Asks for name
		cin >> CD[NumCust].name;  // Allows user to input name which goes into the specific customer's struct
		cout << "Please enter zipcode"; // Asks for zipcode
		cin >> CD[NumCust].zip;  // Allows user to input zip code which goes into the specific customer's struct
		cout << "Enter account balance"; // Asks for account balance
		cin >> CD[NumCust].balance;   // Allows user to input balance which goes into the specific customer's struct
		if (CD[NumCust].balance <= 0){  // Validation to check that the balance is 0 or higher
			cout << "Error, balance must be 0 or greater. Enter again";  // Error message that displays when a negative number is shown
			cin >> CD[NumCust].balance;
		}
		cout << "Enter date of last payment"; // Asks for date of last payment
		cin >> CD[NumCust].lastPay;  // Allows user to input last payment date which goes into the specific customer's struct
		cin.ignore();
	}

	void updatecust(Customer CD[MAXCUST], int NumCust){  // Function for updatecust
		int id;
		int temp;
		cout << "Please enter ID number"; // Asks for an id number (Pre-existing)
		cin >> id;
		temp = findcust(CD, id, NumCust); // Calls findcust and assigns its value to temp
		
		
		cout << "Please enter name"; // Asks for name
		cin >> CD[NumCust].name;  // Allows user to input name which goes into the specific customer's struct
		cout << "Please enter zipcode"; // Asks for zipcode
		cin >> CD[NumCust].zip;  // Allows user to input zip code which goes into the specific customer's struct
		cout << "Enter account balance"; // Asks for account balance
		cin >> CD[NumCust].balance;   // Allows user to input balance which goes into the specific customer's struct
		if (CD[NumCust].balance <= 0){  // Validation to check that the balance is 0 or higher
			cout << "Error, balance must be 0 or greater. Enter again";  // Error message that displays when a negative number is shown
			cin >> CD[NumCust].balance;
		}
		cout << "Enter date of last payment"; // Asks for date of last payment
		cin >> CD[NumCust].lastPay;  // Allows user to input last payment date which goes into the specific customer's struct
		cin.ignore();
	}

	void displaycust(Customer CD[MAXCUST], int NumCust){  //Function for display cust, which displays the customers and their info

		cout << left << setw(15) << "Customer ID" << setw(15) << "Customer Name" << setw(15) << "Zip Code"
			<< setw(15) << "Balance" << setw(15) << "Date Last Paid" << setw(15) << endl;
		cout << setw(15) << "---------" << setw(15) << "-----------" << setw(15) << "------"
			<< setw(15) << "-------" << setw(15) << "---------" << setw(15) << "----------" << endl;
		cout << CD[NumCust].id << setw(15) << CD[NumCust].name << setw(15) << CD[NumCust].zip << setw(15);
		cout << CD[NumCust].balance << setw(15) << CD[NumCust].lastPay << setw(15) << endl;
		cout << "-------------------------------------------------------------------------------------" << endl;
	}


	int findcust(Customer CD[MAXCUST], int id, int NumCust){  // Function for findcust, which finds an existing customer from their id
		int temp = -1;

		for (int k = 0; k < NumCust; k++) {  // For loop to run through the existing information
			if (id == CD[k].id){            //  Matches the id to an existing id if there is one
				temp = k; // Assigns the subscript of the matching id to temp
				
			}
		}
		return temp;

	}

Last edited on
closed account (48T7M4Gy)
addcust(CD, NumCust); // call for addcust

1
2
void addcust(Customer*, int); //prototype
void addcust(Customer* CD, int NumCust)   // Function for addcust 
I tried copying exactly what you said into my code and it solved the problem for a second, then it came right back, just with a few extra things. If I wasn't supposed to just change my words to what you put please let me know and explain what you wanted me to do. Thanks

Btw, here are the errors now:

Error 1 error C2664: 'void addcust(Customer [],int)' : cannot convert argument 2 from 'int *' to 'int' C:\Users\Patrick\Desktop\Proj2\Proj2.cpp 43 1 Proj2

2 IntelliSense: more than one instance of overloaded function "addcust" matches the argument list:
function "addcust(Customer *, int)"
function "addcust(Customer *CD, int &NumCust)"
argument types are: (Customer[30], int)
Last edited on
closed account (48T7M4Gy)
You must have some other error showing up.

Your program with the changes I made above ran to the menu. After that, well it's over to you.

The point I am making with the changes in my suggestions is you can't pass arrays the way you are attempting. Hence the pointer whereby you can. Make the changes and post here. I'll watch out for a short while.
I tried just taking out the & on addcust(CD, NumCust); and now the "No instance of overloaded...." problem is gone. Now its just:

error C2664: 'void addcust(Customer [],int)' : cannot convert argument 2 from 'int *' to 'int'

This is what I currently have for those 3 parts:

1
2
3
4
5
6
7

addcust(CD, NumCust);  // call for addcust

void addcust(Customer, int);  // Function prototype for addcust

void addcust(Customer CD[MAXCUST], int &NumCust){  // Function for addcust

closed account (48T7M4Gy)
Yeah, you still haven't got it. All you need to do is replace 3 lines in your original post with my suggestions for the reason I gave. That will result in you getting your menu to display.

Except for the variable names your prototype should exactly conform to the function body/signature.

You can't pass arrays unless you use a pointer to the array!
Last edited on
Topic archived. No new replies allowed.