#include <iostream>
#include<string>
using namespace std;
int main(int argc, char** argv)
{
do
{
char choice;
cout<<"Menu"
cout<<"A.Information"<<endl;
cout<<"B.Question"<<endl;
cout<<endl<<"Your Choice: ";
cin>>choice;
switch(choice)
{
case 'A':
{
system("cls");
cout<<"All the information";
break;
}
case'B'
{
system("cls");
cout<<"All the question"
break;
default:
{
cout<<"Please enter A or B";
break;
}
}
cout<<"Enter 1 to back to menu or Enter 2 to exit";
cin>>x;
}while(x==1);
=>how Can I return to the menu?<=
=>it also say x is not declared<=
=>is it possible to use continue; in this situation?<=
#include <iostream>
#include<string>
usingnamespace std;
int main(int argc, char** argv)
{
//You had no variable "x", I created it here:
int x;
do
{
char choice;
cout << "Menu"; // You were missing the semicolon
cout << "A.Information" << endl;
cout << "B.Question" << endl;
cout << endl << "Your Choice: ";
cin >> choice;
switch (choice)
{
case'A':
//{ Don't use brackets for individual cases in a switch
system("cls");
cout << "All the information";
break;
//}
case'B': //Missing Colon Here
//{
system("cls");
cout << "All the question"; //Missing semicolon
break;
default:
//{
cout << "Please enter A or B";
break;
//}
}
cout << "Enter 1 to back to menu or Enter 2 to exit";
cin >> x;
}while (x == 1);
//2 slashes are for a single line comment
//This is how to make a multiline comment:
/*
=> how Can I return to the menu ? <=
=> it also say x is not declared <=
=> is it possible to use continue; in this situation ? <=
*/
return 0;
}
They're not needed, just creates a scope for every case - brings no use to him. He didn't properly match the brackets on case 'B'. By making this as simple as possible it makes learning it easier.
A better thing to have said would be, "not needed", but no one's life will change with this minor change.
I forgot to mention that using system() is bad practice.
#include <iostream>
#include<string>
usingnamespace std;
int main(int argc, char** argv)
{
int x;
do
{
char choice;
cout<<"Menu"<<endl;
cout<<"A.Information"<<endl;
cout<<"B.Question"<<endl;
cout<<endl<<"Your Choice: ";
cin>>choice;
switch(choice)
{
case'A':
{
system("cls");
cout<<"All the information"<<endl;
break;
}
case'B':
{
system("cls");
cout<<"All the question"<<endl;
break;
}
default:
{
cout<<"Please enter A or B";
break;
}
}
cout<<"Enter 1 to back to menu or Enter 2 to exit"<<endl;
cout<<"your choice = "; cin>>x;
}while( x == 1 );
return 0;
}