C++ C++;食物菜单(使用do while循环)

C++ C++;食物菜单(使用do while循环),c++,if-statement,do-while,C++,If Statement,Do While,我运行此程序时遇到问题:如果用户选择了yes选项,我试图让用户在菜单上输入他们的选择(A、B、C、D或E)。若并没有,那个么直接计算总销售价格。但每当我选择“是”时,它似乎会重复显示菜单,而不显示选项。请帮助我,我对c++ #include <iostream> #include <iomanip> using namespace std; int main() { double a = 5.99, b = 4.99, c = 4.99, d = 5.99,

我运行此程序时遇到问题:如果用户选择了yes
选项,我试图让用户
在菜单上输入他们的选择(A、B、C、D或E)。若并没有,那个么直接计算总销售价格。但每当我选择“是”时,它似乎会重复显示菜单,而不显示选项。请帮助我,我对
c++

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{

    double a = 5.99, b = 4.99, c = 4.99, d = 5.99, e = 9.99, totalprice;
    const double TAX = 0.13;
    int choice = 0;
    char (answer);

    do
    {

        cout << "\nGood day! Welcome to The Bakery! What would you like today?\n";
        cout << "\nMenu\n                                                        Price"<< endl;
        cout << "A: Earl Gray Tea and Biscuits  -                        $" << a << endl;
        cout << "B: Coffee and a blueberry scone -                       $" << b << endl;
        cout << "C: Espresso and a tea biscuit -                         $" << c << endl;
        cout << "D: Coffee and a Muffin-                                 $" << d << endl;
        cout << "E: The Assorted Tea, Scones, and Biscuits Platter-      $" << e << endl;

        cout << "\nAre there any addtional orders? 'Y' or 'N'\n" << endl;
        cin >> answer;
        if (answer == 'Y' || answer == 'y')

        {   //Display Choice

            cout << "\nYour choice?\n" << endl;
        }


         if (choice == 'A' || choice == 'a')
         {

            cout << "A: Earl Gray Tea and Biscuits" << a << endl;

        }


        if (choice == 'B' || choice == 'b')
        {

            cout << "B: Coffee and a blueberry scone" << b << endl;

        }


      if (choice == 'C' || choice == 'c')
        {

            cout << "A: Earl Gray Tea and Biscuits" << c << endl;

        }


         if (choice == 'D' || choice == 'd')
        {

            cout << "D: Coffee and a Muffin" << d << endl;

        }


        if (choice == 'E' || choice == 'e')
        {

            cout << "E: The Assorted Tea, Scones, and Biscuits Platter" << e << endl;

        }

        else if (answer == 'N' || answer == 'n')
        {
            cin >> totalprice;
            cout << "The final bill for today is ";
        }

        else //Displaying error message
        {
            cout << "Invalid input";
        }

    } while (answer != 'Y' && answer != 'y');

} 
#包括
#包括
使用名称空间std;
int main()
{
双a=5.99,b=4.99,c=4.99,d=5.99,e=9.99,总价;
常数双倍税=0.13;
int-choice=0;
char(答案);
做
{

cout变量选择应该是一个字符,您必须添加cin以接收选择输入

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{

    double a = 5.99, b = 4.99, c = 4.99, d = 5.99, e = 9.99, totalprice;
    const double TAX = 0.13;
    char choice;
    char answer;

    do
    {

        cout << "\nGood day! Welcome to The Bakery! What would you like today?\n";
        cout << "\nMenu\n                                                        Price"<< endl;
        cout << "A: Earl Gray Tea and Biscuits  -                        $" << a << endl;
        cout << "B: Coffee and a blueberry scone -                       $" << b << endl;
        cout << "C: Espresso and a tea biscuit -                         $" << c << endl;
        cout << "D: Coffee and a Muffin-                                 $" << d << endl;
        cout << "E: The Assorted Tea, Scones, and Biscuits Platter-      $" << e << endl;
cin >> choice;
        cout << "\nAre there any addtional orders? 'Y' or 'N'\n" << endl;
        cin >> answer;
        if (answer == 'Y' || answer == 'y')

        {   //Display Choice

            cout << "\nYour choice?\n" << endl;
        }


         if (choice == 'A' || choice == 'a')
         {

            cout << "A: Earl Gray Tea and Biscuits" << a << endl;

        }


        if (choice == 'B' || choice == 'b')
        {

            cout << "B: Coffee and a blueberry scone" << b << endl;

        }


      if (choice == 'C' || choice == 'c')
        {

            cout << "A: Earl Gray Tea and Biscuits" << c << endl;

        }


         if (choice == 'D' || choice == 'd')
        {

            cout << "D: Coffee and a Muffin" << d << endl;

        }


        if (choice == 'E' || choice == 'e')
        {

            cout << "E: The Assorted Tea, Scones, and Biscuits Platter" << e << endl;

        }

        else if (answer == 'N' || answer == 'n')
        {
            cin >> totalprice;
            cout << "The final bill for today is ";
        }

        else //Displaying error message
        {
            cout << "Invalid input";
        }

    } while (answer != 'Y' && answer != 'y');

} 
#包括
#包括
使用名称空间std;
int main()
{
双a=5.99,b=4.99,c=4.99,d=5.99,e=9.99,总价;
常数双倍税=0.13;
字符选择;
答案;
做
{

当你忘了接受你的选择时,你可以做你的选择。这样做会更简单

#include <iostream>
#include <iomanip>
using namespace std;

int main() {

  double a = 5.99, b = 4.99, c=4.99, d=5.99, e=9.99, totalprice;
  const double tax = 0.13;
  char answer;
  char choice;
#包括
#包括
使用名称空间std;
int main(){
双a=5.99,b=4.99,c=4.99,d=5.99,e=9.99,总价;
常数双倍税=0.13;
答案;
字符选择;
然后你会输出你的菜单,询问是否还有其他的订单,并在那里输入答案

do {
  if(answer == 'Y' || 'y') {
    cout << "Your choice?" << endl;
    cin <<  choice
    if(choice == 'A' || choice == 'a') {
      cout << "A: Earl Gray Tea and Biscuits" << a << endl;
      totalprice = totalprice + a;
    } else if(choice == 'B' || choice == 'b') {
      cout << "B: Coffee and a blueberry scone" << b << endl;
      totalprice = totalprice + b;
    } else if(choice == 'C' || choice == 'c') {
      cout << "C: Espresso and a tea biscuit" << c << endl;
      totalprice = totalprice + c;
    } else if(choice == 'D' || choice == 'd') {
      cout << "D: Coffee and a Muffin " << d << endl;
      totalprice = totalprice + d;
    } else if(choice == 'E' || choice == 'e') {
      cout << "E: The Assorted Tea, Scones, and Biscuits Platter " << e << endl;
      totalprice = totalprice + e;
  }
  cout<< "\Are there any additional orders? Y or N << endl;
  cin << answer;
} while(answer != 'N' || answer !='n');
totalprice = totalprice * tax;
cout << "The final bill for today is $" << totalprice << endl;
do{
如果(答案='Y'| |'Y'){

cout
char(answer);
应该是
char-answer;
您没有
cin>>选择;
可以在任何地方阅读用户的选择。1.您从未设置
choice
。2.
choice
是一个整数,但您将其与字符进行比较。