Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;在用户输入的内容上添加多个变量 我不知道该怎么问这个问题,因为我刚开始学C++,我英语不好,很抱歉。p> 所以我在C++中制作了一个餐馆菜单,菜单中有一个项目列表,但问题是我只能选择1个项目并总结它,我如何在菜单中选择多个项目,比如_C++ - Fatal编程技术网

c++;在用户输入的内容上添加多个变量 我不知道该怎么问这个问题,因为我刚开始学C++,我英语不好,很抱歉。p> 所以我在C++中制作了一个餐馆菜单,菜单中有一个项目列表,但问题是我只能选择1个项目并总结它,我如何在菜单中选择多个项目,比如

c++;在用户输入的内容上添加多个变量 我不知道该怎么问这个问题,因为我刚开始学C++,我英语不好,很抱歉。p> 所以我在C++中制作了一个餐馆菜单,菜单中有一个项目列表,但问题是我只能选择1个项目并总结它,我如何在菜单中选择多个项目,比如,c++,C++,菜单列表 食物1 食物2 食物3 选择上面的项目:1 3 然后显示什么是用户输入的列表,并总结它和它的价格 我在考虑使用while循环,当用户输入字符'c'意味着签出时,它将对所有内容进行汇总您需要做的是使用一个标志变量来确定用户是否完成了向购物车添加物品的操作 例如,界面如下所示 Menu list - food 1 food 2 food 3 - quit (q) 然后,只需查看输入是否==“q”,如果是,则中断循环 while(true){ cin << input

菜单列表

  • 食物1
  • 食物2
  • 食物3
  • 选择上面的项目:1 3 然后显示什么是用户输入的列表,并总结它和它的价格


    我在考虑使用while循环,当用户输入字符'c'意味着签出时,它将对所有内容进行汇总

    您需要做的是使用一个标志变量来确定用户是否完成了向购物车添加物品的操作

    例如,界面如下所示

    Menu list
    -
    food 1
    food 2
    food 3
    -
    quit (q)
    
    然后,只需查看
    输入是否==“q”
    ,如果是,则中断循环

    while(true){ 
        cin << input;
        if(input == "q") break;
        else //other-logic-here
    }
    
    while(true){
    
    cin您需要做的是使用一个标志变量来确定用户是否已完成向购物车添加物品的操作

    例如,界面如下所示

    Menu list
    -
    food 1
    food 2
    food 3
    -
    quit (q)
    
    然后,只需查看
    输入是否==“q”
    ,如果是,则中断循环

    while(true){ 
        cin << input;
        if(input == "q") break;
        else //other-logic-here
    }
    
    while(true){
    
    cin实现您想法的方法:

    const int menu[]{ 10,20,30 };
    int a=0, b=0, c=0;
    
    cout << "enter your mix.(a=10,b=20 and c=30). Press other keys to sum." << endl;
    char input;
    cin >> input;
    
    while (input != 'q')
    {
        switch (input)
        {
            case 'a'  :a += menu[0]; break;
            case 'b'  :b += menu[1]; break;
            case 'c'  :c += menu[2]; break;
            default:
                cout << a << " + " << b << " + " << c <<" = "<<  a + b + c << endl;
                a = b = c = 0;
                cout << "enter a,b,or c." << endl;
        }
        cin >> input;
    }
    

    实现您想法的方法:

    const int menu[]{ 10,20,30 };
    int a=0, b=0, c=0;
    
    cout << "enter your mix.(a=10,b=20 and c=30). Press other keys to sum." << endl;
    char input;
    cin >> input;
    
    while (input != 'q')
    {
        switch (input)
        {
            case 'a'  :a += menu[0]; break;
            case 'b'  :b += menu[1]; break;
            case 'c'  :c += menu[2]; break;
            default:
                cout << a << " + " << b << " + " << c <<" = "<<  a + b + c << endl;
                a = b = c = 0;
                cout << "enter a,b,or c." << endl;
        }
        cin >> input;
    }