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
#include <iostream>
#include <string>
usingnamespace 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"};
constint 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;
}
}
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?
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.