switch statement error

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
switch (choice) //error transfer of control
		{
		case 'G':
			{
				int key;
				cout << "What part number do you want information on?" << endl;
				cout << "Enter the part number " << endl; 
				cin >> key;
			
				int i=0;
				for (i=0; i < SIZE; i++)
				{
					if (key == database[i].partNum)
					break;
				}
				if ( i >= SIZE)
				{
					cout << "Error. Incorrect part number" << endl;
				}
				else 
				{
					disp_database(database);//disp database

				}
				break;
			}
		case 'D':
			{
				cout << "Display database" << endl;
				break;
			}
		case 'O':
			{
				cout << "Place the order" << endl;
				break;
			}
		case 'R':
			{
				cout << "Enter part number and quantity" << endl;
				break;
			}
		case 'E':
			{
				ofstream outfile;
				outfile.open("parts.out");
				for(int i=0 ; i < SIZE ; i++)
				{
					outfile << database[i].partNum << '  ';
					outfile << database[i].partName << '  ';
					outfile << database[i].Price << '  ';
					outfile << database[i].Qty << endl;
				}
				outfile.close();
				break;
				default:
				cout << "Not a valid choice. Choose again" << endl;
				cin >> choice;
				break; 
			}

			return 0; 
		}
Last edited on
Use code-tags, explain what variables SIZE, database, etc are or, better still, post your entire program and point out where exactly the error lies
Topic archived. No new replies allowed.