**已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
22小时前关门了。
Improve this question
我正在做一个多菜单,但我需要一种方法来返回到主菜单时,用户类型“0”
1.我尝试插入while(choice ==0),但输入0时无法跳回到主菜单
1.在第一种情况下(选择语言菜单),我可以返回主菜单,但在其他情况下,当输入0时,我无法返回主菜单
- Sry的代码是如此之多,因为这是第一次,我创建了一个程序与多菜单,想听听你们的建议,如何改善我的代码
1.我通过使用Do-while方法和在do-while中使用switch case方法来完成这个程序。
#include <string>
#include <iostream>
using namespace std;
int main()
{
int choice;
cout << endl << "-------------------------------------" << endl;
cout << endl << " Welcome to Our Book Store " << endl;
cout << endl << "-------------------------------------" << endl;
do
{
//choosing language menus
cout<<"\n1. Malay\n2. English\n3. Chinese\n";
cout<<"Type your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\n1=horror\n";
cout<<"2=love\n";
cout<<"3=comedy\n";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nChoose Horror Book\n";
cout<<"\n1. Hantu dalam rumah kamu Rm20";
cout<<"\n2. Bapa saya hantu Rm30";
cout<<"\n3. China HantuR Rm50";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Pada suatu hari.............";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 2:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Pada suatu hari, bapa saya menjadi hantu.............";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 3:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Pada suatu hari, hantu dari china.............";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
}
return 0;
case 2:
cout<<"\nChoose love Book\n";
cout<<"\n1. Romeo dan Julia";
cout<<"\n2. Mr. London Ms.Langkawi";
cout<<"\n3. KL. Noir: Red";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Romeo take me, somewhere we can be alone...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 2:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Romeo take me, somewhere we can be alone...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 3:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Romeo take me, somewhere we can be alone...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
}
case 3:
cout<<"\n Choose Comedy Book\n";
cout<<"\n1. Nasi Lemak Story";
cout<<"\n2. Apa yang laku";
cout<<"\n3. Sayang Bapakau";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Wish I can be Nasi Lemak...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 2:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Wish I can be Nasi Lemak...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
}
}
// case for choosing language
case 2:
cout<<"1=horror\n";
cout<<"2=love\n";
cout<<"3=comedy\n";
cout<<"\nType your choice: ";
cin>>choice;
switch (choice)
{
case 1:
cout<<"\n1. Ghost Hunter";
cout<<"\n2. Demon Slayer";
cout<<"\n3. Doctor Ghost";
cout<<"\nType your choice: ";
cin>>choice;
switch (choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Gun, cross, pray are all what Ghost Hunter need...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 2:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Demon Slayer are born to kill demon, whatever it take...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 3:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Weirld doctor living in a castle...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
}
case 2:
cout<<"\n1.A kind of sad";
cout<<"\n2. Loving Beijing 101";
cout<<"\n3. Love you 3000";
cout<<"\nType of choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Cancer is their enemy...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 2:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Beijing, a place full of pressure and love...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 3:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Last word Ironman said....";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
}
case 3:
cout<<"\n1. laughing 1";
cout<<"\n2. laughing 2";
cout<<"\n3. laughing 3";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"so funny hahahaha";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 2:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"so funny huhuhuuuuuuuu";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 3:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"so funny aaaaaaaahahahahah";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
}
}
// case for choosing language
case 3:
cout<<"1=horror\n";
cout<<"2=love\n";
cout<<"3=comedy\n";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\n1. China Ghost story";
cout<<"\n2. Story of Apollo Hotel";
cout<<"\n3. Little town story";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"China, A big country with weird place";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 2:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Apollo Hotel, Hotel full of Apollo...";
cout<<"\n1. Proceed to checkout";
cout<<"\n0. Return to Main menu";
cout<<"\nType your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"--------------------------------\n";
cout<<"Thank you!\n";
cout<<"Pls come again~";
return 0;
}
case 3:
cout<<"--------------------------------\n";
cout<<"\nDescription: \n";
cout<<"Two Lovers first meet at the town...";
cout<<"\nType your choice: ";
break;
}
break;
}
}
return 0;
} while(choice ==0);
}
1条答案
按热度按时间mm9b1k5b1#
一个问题是这里缺少
break
应该是
但是说真的,停止你现在正在做的事情,把一些子菜单放到单独的函数中,代码变得非常非常笨拙。