Compilation error, where did I go wrong?

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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#include <iostream>

using namespace std;

//include protype functions

int main()

{

char choice;

bool terminate = false;

const int SIZE = 100;

int i = 0;


enum AccountType 

{unknown = -1, Checking, Savings, CreditCard, InstantAccess};


struct customerInfo 

{

char firstName[20]; 

char lastName[20];

float amount;

AccountType type;

}

customerInfo[SIZE];

//float depositAmount (){};

//float withdrawAmount (){};

while (!terminate)

{

cout << "WELCOME TO SO-AND-SO BANK!\n\n" << "Please enter an option, are you a:\n\n" 

<< "A)Customer\n" 

<< "B)Bank Employee\n" 

<< "C)Bank Supervisor\n" 

<< "D)Quit the application\n\n";

cin >> choice;

switch(choice)

{

case 'a':

case 'A':

cout << "Welcome to So-and-So Bank Customer Services!\n" << "Please enter an option:\n\n";

//Customer options

cout << "A)Functions: Balance Inquiry\n" 

<< "B)Deposit Funds\n" 

<< "C)Withdraw funds\n"

<< "D)Transfer Funds to another account (like from Checking to Savings or to Credit Card)\n"

<< "E)Anything else that you want to add\n" 

<< "F)Quit the application\n\n";

cin >> choice;

switch(choice)

{

case 'a':

case 'A':

//struct name, amount, type

for(i = 0; i < SIZE; i++) //edit

{

cout << "Enter your first name (20 characters or less):\n\n";

cin >> customerInfo[i].firstName;

cout << "Enter your last name (20 characters or less):\n\n";

cin >> customerInfo[i].lastName;

};

break;

case 'b':

case 'B':

//depositAmount();

break;

case 'c':

case 'C':

//withdrawAmount();

break;

case 'd':

case 'D':

//transfer enum

break;

case 'e':

case 'E':

//while or goto loop

break;

case 'f':

case 'F':

cout << "You have chosen to quit, we appreciate your business.";

terminate = true;

break;

default:

cout << "You have entered an invalid option, please try again.\n\n";

break;

}

break;

case 'b':

case 'B':

cout << "Welcome to So-and-So Bank Employee Services!\n" << "Please enter an option:\n\n";

//Cascading customer data

//a.Everything in the Customer Interface, plus

cout << "A)Interface to ADD a new Customer to the Bank\n"

<< "B)Interface to DELETE a Customer from the Bank\n"

<< "C)Search for a Record based on a Name of a Customer (using simple Sequential Search)\n"

<< "D)Quit the application\n\n";

cin >> choice;

switch(choice)

{

case 'a':

case 'A':

//struct new customer

for(i = 0; i < SIZE; i++) //edit

{

cout << "Enter your first name (20 characters or less):\n\n";

cin >> customerInfo[i].firstName;

cout << "Enter your last name (20 characters or less):\n\n";

cin >> customerInfo[i].lastName;

};

break;

case 'b':

case 'B':

//struct delete customer (Case C w/ remove name)

break;

case 'c':

case 'C':

//for loop name search, cin i, i customer

cout << "So-and-So Bank Customers:\n";

for(i = 0; i < SIZE; i++)

{

cout << i << ". " << customerInfo[i].lastName << ", " << customerInfo[i].firstName << "\n";

};

cout << "Select customer number:\n\n";

cin >> i;

cout << customerInfo[i];


break;

case 'd':

case 'D':

cout << "You have chosen to quit, we appreciate your business.";

terminate = true;

break;

default:

cout << "You have entered an invalid option, please try again.\n\n";

break;

}

break;

case 'c':

case 'C':

cout << "Welcome to So-and-So Bank Supervising Services!\n" << "Please enter an option:\n\n";

//Cascading banker and customer data

//a.Everything in Bank Teller Interface, plus

cout << "A)Ability to List Total Number of Customers in Bank\n"

<< "B)Ability to List Total Amount of Money in the Bank\n"

<< "C)Ability to List Total Deposits in a Day\n"

<< "D)Ability to List Total Withdrawals in a Day\n"

<< "E)Ability to see/query detailed LOG of all transactions\n"

<< "F)Quit the application\n\n";

cin >> choice;

switch(choice)

{

case 'a':

case 'A':

//for loop count customers

break;

case 'b':

case 'B':

//for loop count money 

break;

case 'c':

case 'C':

//for loop count deposits (amount?)

break;

case 'd':

case 'D':

//for loop count withdrawals (amount?)

break;

case 'e':

case 'E':

//enum results from b,c, and d. for loop allow search

break;

case 'f':

case 'F':

cout << "You have chosen to quit, we appreciate your business.";

terminate = true;

break;

default:

cout << "You have entered an invalid option, please try again.\n\n";

break;

}

break;

case 'd':

case 'D':

cout << "You have chosen to quit, we appreciate your business.";

terminate = true;

break;

default:

cout << "You have entered an invalid option, please try again.\n\n";

break;

}

}

return 0;

}
What exactly is the error...?
It's a warning about the use of customerInfo (line 239). Is there something I did wrong there?
Yes, cout doesn't know how to output your structure. You either need to output the stuff yourself or make an overload for operator <<.
Argh! How can you read that? Use some formatting and indentation! I recommend you to a pretty printer.
http://www.softpanorama.org/Utilities/beautifiers.shtml

The error I get is:
a.cpp:239: error: no match for 'operator<<' in 'std::cout << customerInfo[i]'

That is, you are trying to print an entire struct, but you have not provided an operator<<() overload to do it.

In C++, you typically declare types outside the main() function, then instantiate it as you would any other variable. Also, it is typically bad practice to rely on the struct namespace to distinguish your type from a variable.
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
#include <iostream>
#include <limits>
using namespace std;

// class definitions typically go outside functions
struct pair_t
  {
  int left;
  int right;
  };

// an output operator to display the class
ostream& operator << ( ostream& outs, const pair_t& pair )
  {
  outs << "(" << pair.left << "," << pair.right << ")";
  return outs;
  }

// a little funtion for this example to read an integer
int read_int( const char* prompt, const char* error_message )
  {
  int result;
  cout << prompt << flush;
  for (;;)
    {
    bool ok = (cin >> result);
    cin.clear();
    cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
    if (ok) break;
    cout << error_message << '\n' << prompt << flush;
    }
  return result;
  }

int main()
  {
  // using the class
  pair_t two_random_numbers;
  cout << "Please enter two integer numbers:\n";
  two_random_numbers.left  = read_int( "one> ", "Try again." );
  two_random_numbers.right = read_int( "two> ", "Try again." );
  cout << "You entered the pair: " << two_random_numbers << ".\n";
  return 0;
  }


Hope this helps.

[edit] hmm... can't make chocolate cake and respond to posts at the same time...
Last edited on
Mmmm... smells good... chocolate...
Topic archived. No new replies allowed.