Need to update array

The previous problem was solved, but however when i added a restaurant to the menu, the current_size won't update, can anyone help me how to fix this? Thank you!
Here is my code so far

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
#include <iostream>
#include <string>

using namespace std;


int main()
{
	bool makan = true;
	bool found = false;
	string del;
	string resto[] = {"Applesbees","Betos","Cafe Rio","Dairy Queen","Edo Japan","Fazoli's","Golden Corral","Hot Dog on a stick"};
	const int max_size = 16;			
	int now = sizeof(resto)/sizeof(*resto);
	int current_size = now;
	
	while (makan)
	{
			cout<<"The Menu	"<<endl;
			cout<<"1. Display All restaurants"<<endl;
			cout<<"2. Add a restaurant"<<endl;
			cout<<"3. Remove a restaurant"<<endl;
			cout<<"4. Randomly rearrange the restaurants"<<endl;
			cout<<"5. Begin the tournament"<<endl<<endl;
			cout<<"Your choice : "; 
			int choice;
			
		
			cin>>choice;
			switch (choice)
			{
			case 1: for (int a=0; a<now; a++)
					{cout<<resto[a]<<endl;}
					cout<<endl;
					system ("Pause");
					system ("CLS");
					makan;continue;break;

			case 2:		  				
						 if (current_size < max_size)
						  {
							  cout<<"Enter the name of the restaurant you want to add : ";
							  string add; cin>>ws; getline(cin,add);
									  for(int pos=0; pos<current_size; pos++)
								{
									if ( add == resto[pos] )
									{
										found = true;
										cout << "The restaurant is already in the list!" << endl;
										break;								
									}
								}
								if (!found)
								{
									resto[current_size - 1] = add;
									cout << "The restaurant is successfully added to the list!" << endl;
								}							  						  				  
						  }
						 else
						 {
							 cout << "Number of restaurant is already maxed!" << endl;
						 }
						 
					system ("Pause");		
					system ("CLS");
					makan;
					continue;
					break;

			case 3:		cout << "Type in the name of the restaurant you want to delete : ";
						cin>>ws;
					    getline(cin,del);
						for(int pos=0; pos<current_size; pos++)
						{
							if ( del == resto[pos] )
							{
								found = true;
								resto[pos] = "";
								current_size--;
								cout << "The restaurant was successfully deleted!" << endl; // masih ada blank space//
								break;								
							}
						}
						if (!found) cout <<"Wrong input, not found" << endl;

					system ("Pause");		
					system ("CLS");
					makan;continue;break;

			case 4: for (int x=0; x < current_size - 1; x++)
					{
						string temp = resto[x];
						resto[x] = resto[x+1];
						resto[x+1] = temp;   // masih belom sempurna tapi ide nya udah dapet //
					}
				
					cout<<"Restaurant successfully rearranged!"<<endl;
					system ("Pause");
					system ("CLS");
					makan;continue;break;

			case 5: if (current_size != max_size) { cout << "Tournament cannot be started until numbers of restaurant is 16!" << endl;}
					system ("Pause"); system ("CLS");
					makan;continue;break;
			
			}

			system("Pause");
			return 0;
	}
	
}
Last edited on
First of all it is a bad idea to use the same name for two different entities

bool resto = true;
string resto[] = {"Applesbees","Betos","Cafe Rio","Dairy Queen","Edo Japan","Fazoli's","Golden Corral","Hot Dog on a stick"};


Secondly it is also a bad idea to use continue in switch statement

1
2
3
4
5
6
7
8
			case 1: for (int a=0; a<now; a++)
					{cout<<resto[a]<<endl;}
					cout<<endl;
					system ("Pause");
					system ("CLS");
					resto;
					continue;
				break;


Thirdly your array resto is local for the while statement so all changes in it are lost after each iteration.
thank you for your reply, but why is it a bad idea to use continue in switch statement? if i delete the continue, the program wont go back to the menu again. thanks.
thank you for your reply, but why is it a bad idea to use continue in switch statement? if i delete the continue, the program wont go back to the menu again. thanks.


That's because your loop isn't really a loop. Instead of allowing it to loop, you return from it.

Lines 93 and 94 should be outside the loop.

All of the lines that say resto; have no meaningful effect (and I'm sure your compiler warns you about that.) What exactly did you expect to happen on those lines?
so that the condition is back to true and the menu appears again, so that it repeats while the condition is set to true.
The condition will be true until you change it. You never change it, thus it will always be true. Doing that has absolutely no effect at all on the program. At that point, it isn't even what you think it is. resto refers to the array of strings everywhere it occurs within the loop, not the boolean variable you're "looping" on.
Topic archived. No new replies allowed.