control paths

Hi;
Not all control paths return a value 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
 do
 {
		system("cls");
		selection = displayMenu();
	
	switch(selection)
	{
		case 'A': update =  optionA(tele,newSize );
		break;
		case 'D': update = optionD(tele,newSize);
		break;
		case 'U': update =  optionU(tele,newSize );
		break; 	
		case 'L': optionL(tele, newSize );
		break;
		case 'E' : EXIT == update;  ////<========   (whats up with this)
		break;	
		case 'F' : cout << " Invaid choice " << endl;
	}
	
  }    while(!EXIT );
 
  
	system("pause");

Whats up with my == sign when I make it = it says isual studio 2010\projects\whatshesent\whatshesent\newnew.cpp(426): error C2106: '=' : left operand must be l-value
========== Build: 0 succeeded, 1 failed, 0 up-to-da

But when I have == it says that it has no effect but yet my program stops when I want it to ..ha Whats the deal?? Thanks
What is the entire function this is in? You aren't returning anything in that code piece so if it is in a function that should be returning something then that is why you are getting that error.

What is EXIT?
I'm having issues with my program returing to main menu after a function. (or doing the function again for that matter) I have switch at the end. I'm not sure if the issue is with that or not. It won't return to main menu properly If you select y or n it just ends. It wasn't when I first finished. Please help..


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
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

//Constants
const int SIZE = 10;

//Enum
enum progress{ MENU, CONTINUE, EXIT} update;

//Structure
struct infoType
{	
	string fname;
	string lname;
	string streetAdd;
	string cityStateZ;
	string phone;






};

// Function to get info from file.
void readData(ifstream &fin, infoType tele[], int& size)
{	
	
	int i = 0;
	while(!fin.eof())
   {
		fin >> tele[i].fname;
		fin >> tele[i].lname;
		fin.get();
		getline(fin,tele[i].streetAdd,'\n');
		getline(fin,tele[i].cityStateZ,'\n');
		getline(fin,tele[i].phone,'\n');
	i++;
   }
		size = i;
}

//Function to display Menu
char displayMenu()
{	
	//Variables
	char choice = ' ';

	//User menu
	cout << "Phone Directory Program " << endl;
	cout << endl;
	cout << "Options" << endl;
	cout << "[A]dd and entry to the phone directory. " << endl;
	cout << "[D]elete an entry from the phone directory. " << endl;
	cout << "[U]pdate an entry from the phone directory. " << endl;
	cout << "[L]ist the entire phone directory. " << endl;
	cout << "[E]xit the menu" << endl;
	//Get choice
	cout << "Please enter option selection. " << endl;
	cin >> choice;
	
	//Convert to uppercase
	choice = toupper(choice);
	
	//Control structure to return char to main.
	switch(choice)
	{
		case 'A': return 'A';
		break;
		case 'D': return 'D';
		break;
		case 'U': return 'U';
		break;
		case 'L': return 'L';
		break;
		case 'E': return 'E';
		default: cout << "Invalid choice." << endl;
				  return 'F';
	}

}

//Option A Function
progress optionA(infoType tele[], int& size)
{	
	//Variables
	char iterate = ' ';
	char choice = ' ';
	int index = size;
	
 while(iterate)
 {
	//Message for option A function
	cout << "----You have selected option A---- " << endl;
	cout << endl;
	
	//To get last name
	cout << "Please enter the last name. " << endl;
	cin.get();
	getline(cin,tele[index].lname);
	
	//Convert first letter to uppercase
	tele[index].lname[0]= toupper(tele[index].lname[0]);
	
	//To get first name
	cout << "Please enter the first name. " << endl;
	getline(cin, tele[index].fname);
	
	//To convert to uppercase
	tele[index].fname[0]= toupper(tele[index].fname[0]);
	
	//To get address
	cout << "Please enter the street address. " << endl;
	getline(cin,tele[index].streetAdd); 
	
	//To get city,state,zip
	cout << "Please enter the city, state and zip code." << endl;
	getline(cin,tele[index].cityStateZ); 
	
	//To get phone
	cout << "Please enter the phone number.(Example, 555-555-5555)" << endl;
	getline(cin, tele[index].phone); 
	size ++;
	
	// User option
	cout << "Would you like to add another entry," << endl;
	cout << "Y/N?" << endl;
	cin >> choice;
	choice = toupper(choice);
	
	//Choice options 
	switch(choice)
	{
	 case 'Y': iterate = choice;
		 break;
	 case 'N': return MENU;
		 break;
	 default: cout << "Invalide choice, returning to Main Menu." << endl;
		 return MENU;
	 }
  }
}

//Option U Function
progress optionU( infoType tele[], int&size )
{	
	//Variables
	int index = 0;
	string lname = "";
	string newLname = "";
	string newFname = "";
	string newAdd = "";
	string newCSZ = "";
	string newPhone = "";
	int choice = 0;
	char choice2 = ' ';
	char iterate = ' ';
	bool found = false;
	
 while(iterate)
 {
	//Option U function message
	cout << "----You have selected option U.----" << endl;
	
	// To get record.
	cout << "Please enter the last name of record to be updated." << endl;
	
	//Get last name
	cin >> lname;
	
	//Convert first letter to upper
	lname[0] = toupper(lname[0]);
	
	//Find record
	while( index < size && !found )
	{
	  if(tele[index].lname.compare(lname)== 0)
	  {
		cout << "The entry to be updated is " << endl;
		cout << tele[index].lname << endl;
		cout << tele[index].fname << endl;
		cout << tele[index].streetAdd << endl;
		cout << tele[index].cityStateZ << endl;
		cout << tele[index].phone << endl;
		cout << endl;
		    found = true;
	  }
		else if(!found)
		index++;
	}
	
	// If Entry is not located
	if(index == size)
		{
			cout << "Cannot Locate entry." << endl;
			cout << "Returning to menu." << endl;
			return MENU;
		}
	
	//User prompt
	cout << "Please select from one of the following" << endl;
	cout << "1. Update last name." << endl;
	cout << "2. Update first name." << endl;
	cout << "3. Update street Address." << endl;
	cout << "4. Update city, state, and zip code." << endl;
	cout << "5. Update phone number." << endl;

	// To get selection	
	cout << "Enter choice" << endl;
	cin >> choice;
	switch(choice)
	{
	case 1: cout << "Please type the new last name. " << endl;
		cin.get();
		getline(cin,newLname);
		newLname[0] = toupper(newLname[0]);
		tele[index].lname = newLname;
		break;
	case 2: cout << "Please type the new first name. " << endl;
		cin.get();
		getline(cin, newFname);
		tele[index].fname = newFname;
		break;
	case 3: cout << "Please type the new  street address" << endl;
		cin.get();
		getline(cin,newAdd); 
		tele[index].streetAdd = newAdd;
		break;
	case 4: cout << "Please type the new  city, state, and zip code." << endl;
		cin.get();
		getline(cin,newCSZ); 
		tele[index].cityStateZ = newCSZ;
		break;
	case 5: cout << "Please type the new phone number."<< endl;
		cout << "(Example, 555-555-5555) " << endl;
		cin.get();
		getline(cin, newPhone);
		tele[index].phone = newPhone;
		break;
	default: cout << "Invalid selection. " << endl;
			 cout << "Returning to Main Menu." << endl;
			 return MENU;
	}
	//Display updated entry updated
	cout << endl;
	cout << "Updated information. " << endl;
	cout << tele[index].lname << endl;
	cout << tele[index].fname << endl;
	cout << tele[index].streetAdd << endl;
	cout << tele[index].cityStateZ << endl;
	cout << tele[index].phone << endl;
	
	//User option
	cout << "Would you like to update another entry," << endl;
	cout << "Y/N?" << endl;
	cin >> choice2;
	choice2 = toupper(choice2);
	
	//Choice options 
	switch(choice2)
	{
	 case 'Y': iterate = choice2;
		 break; 
	 case 'N': return MENU;
		 break;
	 default: cout << "Invalide choice, returning to Main Menu." << endl;
		 return MENU;
	}
  
  }

}
Here is rest.. Sorry for length I have given where I think the issue is above in my description of problem

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
//Option D Function 
progress optionD( infoType tele[], int& size )
{	
	//Variables
	int index = 0;
	bool found = false;
	string dPhone;
	char iterate = ' ';
	char choice = ' ';
	
  while(iterate)
  {	
	//message for option D function
	cout << "----You have selected option D---- " << endl;
	cout << "Please enter the phone number of the record to be deleted." << endl;
	cout << "(Example, 555-555-5555)" << endl;
	
	//get number
	cin >> dPhone;
	
	//Show information at index and "delete." 
	while( index < size && !found )
	{
		if(tele[index].phone.compare(dPhone)== 0)
		{
			cout << "The entry to be deleted is " << endl;
			cout << tele[index].lname << endl;
			cout << tele[index].fname << endl;
			cout << tele[index].streetAdd << endl;
			cout << tele[index].cityStateZ << endl;
			cout << tele[index].phone << endl;
			cout << endl;
		//To "remove" element.
			--size;
			tele[index] = tele[size];
			found = true;
	     }
			else if(!found)
			index++;
	}
	
	//Message if not found
	if(index == size && !found)
	{
		cout << "Cannot Locate entry." << endl;
		cout << "Returning to Main Menu." << endl;
		return MENU;
	}

	//User option
	cout << "Entry deleted " << endl;
	cout << "Would you like to delete another entry," << endl;
	cout << "Y/N?" << endl;
	cin >> choice;
	choice = toupper(choice);
	
	//Choice options 
	switch(choice)
	{
	 case 'Y': iterate = choice;
		 break;
	 case 'N': return MENU;
		 break;
	 default: cout << "Invalide choice, returning to Main Menu." << endl;
		 return MENU;
	}	
  }
}

//Sort Function
 void sort(infoType tele[], const int& size)
 {
	
	int i, j;
	int smallest;
	
	for (i = 0; i < size - 1; i++)
	{
		smallest = i;

		for (j = i + 1; j < size; j++)
		{
			if (tele[j].lname != "" && tele[smallest].lname != "")
			{	
				 if( tele[j].lname <  tele[smallest].lname )
				{
					smallest = j;
				}
			}
		}
			//swap
			infoType temp = tele[smallest];
			tele[smallest] = tele[i]; 
			tele[i] = temp;              
	}
}

 //Option L Function 
progress optionL( infoType tele[], const int& size)
{	//Variables
	char r = ' ';
	
	//Sorting function
	sort(tele,size);
	
	//Listing
	cout << "----Phone Directory---- " << endl;
	cout << endl;
	for(int index = 0; index < size; index++)
	{
		cout << tele[index].lname << endl;
		cout << tele[index].fname << endl;
		cout << tele[index].streetAdd << endl;
		cout << tele[index].cityStateZ << endl;
		cout << tele[index].phone << endl;
		cout << endl;
	}
	//Return to Menu
	cout << "Enter 'R' to return to the Main Menu. " << endl;
	cin >> r;
	r = toupper(r);
	return MENU;
}

int main()
{	
	ifstream fin("input.txt");
	int newSize = 100;
    infoType tele[SIZE];
	char selection = ' ';
	
	readData(fin, tele, newSize );	
	
  do
 {
		system("cls");
		selection = displayMenu();
	
	switch(selection)
	{
		case 'A': update =  optionA(tele,newSize );
		break;
		case 'D': update = optionD(tele,newSize);
		break;
		case 'U': update =  optionU(tele,newSize );
		break; 	
		case 'L': optionL(tele, newSize );
		break;
		case 'E' : EXIT == update;   //Stupid ==
		break;	
		case 'F' : cout << " Invaid choice " << endl;
		break;
	}
	
  }    while(!EXIT );
 
  
	system("pause");
 
 return 0;

}
Last edited on
1
2
3
enum progress{ MENU, CONTINUE, EXIT} update;
//...
case 'E' : EXIT == update;  ////<========   (whats up with this 

there is the problem.
Enums internally translates to integers. When you write
EXIT = update
it equals to
2 = update
Which is nonsence: you cannot change value of "2"
You probably mean to write
update = EXIT
Yes you are correct. Instead I have done this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
switch(selection)
	{
		case 'A': update =  optionA(tele,newSize );
		break;
		case 'D': update = optionD(tele,newSize);
		break;
		case 'U': update =  optionU(tele,newSize );
		break; 	
		case 'L': optionL(tele, newSize );
		break;
		case 'E' : update = EXIT;   //Stupid ==
		break;	
		case 'F' : cout << " Invaid choice " << endl;
		break;
	}
	
  }    while(update!= EXIT );
 
Topic archived. No new replies allowed.