C++ 编写一个程序,使用枚举类型c+销售爆米花和饮料+;班

C++ 编写一个程序,使用枚举类型c+销售爆米花和饮料+;班,c++,C++,我的任务是:编写一个使用枚举类型销售爆米花和饮料的程序。您必须在您的应用程序中使用以下内容: 节目: 枚举大小{小、中、大、巨型}; 大小爆米花大小,饮用; 您应该创建一个菜单,要求用户选择他们想要的饮料的大小,并选择饮料的大小 他们想要爆米花。然后你应该打印出饮料和爆米花的总成本 价格: 小爆米花=1.25,中爆米花=2.25,大爆米花=3.50,特大爆米花=4.25 小苏打=1.50,中苏打=2.50,大苏打=3.75,大苏打=4.50 这是我的密码: int main() { en

我的任务是:编写一个使用枚举类型销售爆米花和饮料的程序。您必须在您的应用程序中使用以下内容: 节目: 枚举大小{小、中、大、巨型}; 大小爆米花大小,饮用; 您应该创建一个菜单,要求用户选择他们想要的饮料的大小,并选择饮料的大小 他们想要爆米花。然后你应该打印出饮料和爆米花的总成本

价格: 小爆米花=1.25,中爆米花=2.25,大爆米花=3.50,特大爆米花=4.25 小苏打=1.50,中苏打=2.50,大苏打=3.75,大苏打=4.50

这是我的密码:

int main()
{
    enum sizes { SMALL, MEDIUM, LARGE, JUMBO };
    sizes popcornSize, drinkSize;

    double sp=1.25, mp=2.25, lp=3.50, jp=4.25, TOTALp, TOTALs, ss=1.50,         ms=2.50, ls=3.75, js=4.50 ;
    char choice, answer, Psize, Ssize;
    int how_many;
    cout << "Hello I am selling popcorn and sodas, would you like to buy  some? type yes or no please." << endl;
    cin >> choice;
    if (choice == 'yes')
    {
        cout << "Great, what would you like popcorn or soda? Type P for popcorn and S for soda." << endl;
        cin >> answer;
        if (answer = 'P')
        {
            cout << "what size popcorn would you like (type s for small, m for medium, l for large or j for jumbo) and how many (type a single number)?" << endl;
            cin >> Psize >> how_many;
            if (Psize = 's')
            {
                TOTALp = sp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }
            else if (Psize = 'm')
            {
                TOTALp = mp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }
            else if (Psize = 'l')
            {
                TOTALp = lp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }
            else if (Psize = 'j')
            {
                TOTALp = jp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }


            else if (answer = 'S')
            {

                cout << "what size soda would you like (type small, medium, large or jumbo) and how many (type a single number)?" << endl;
                cin >> Ssize >> how_many;
                if (Ssize = 's')
                {
                    TOTALs = ss*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }
                else if (Ssize = 'm')
                {
                    TOTALs = ms*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }
                else if (Ssize = 'l')
                {
                    TOTALs = ls*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }
                else if (Ssize = 'j')
                {
                    TOTALs = js*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }

            }
            cout << "Thanks for buying come again soon." << endl;
        }

        }
        else if (choice == 'no')
            cout << "Okay have a great day!" << endl;
    return 0;
}
intmain()
{
枚举大小{小、中、大、巨型};
大小爆米花大小,饮用;
双sp=1.25,mp=2.25,lp=3.50,jp=4.25,TOTALp,TOTALs,ss=1.50,ms=2.50,ls=3.75,js=4.50;
字符选择,回答,心灵感应,心灵感应;
int多少;
不能选择;
如果(选项==“是”)
{
答不上来;
如果(答案='P')
{
想一想>>有多少人;
如果(Psize='s')
{
TOTALp=sp*多少;

不能程序结束,因为选项从来不是“是”或“否”。因为选项是字符,所以它只能是单个字符。将“是”更改为“y”,将“否”更改为“n”,它应该可以工作

我给出了一个如何编写switch语句的示例,以便在代码的其余部分对其进行调整

#include "stdio.h"
#include "iostream"

using namespace std;

int main()
{
    enum sizes { SMALL, MEDIUM, LARGE, JUMBO };
    sizes popcornSize, drinkSize;

    double sp=1.25, mp=2.25, lp=3.50, jp=4.25, TOTALp, TOTALs, ss=1.50,         ms=2.50, ls=3.75, js=4.50 ;
    char choice, answer, Psize, Ssize;
    int how_many;
    cout << "Hello I am selling popcorn and sodas, would you like to buy  some? type yes or no please." << endl;
    cin >> choice;
    switch(choice)
    {
    case 'y':
        cout << "Great, what would you like popcorn or soda? Type P for popcorn and S for soda." << endl;
        cin >> answer;
        if (answer = 'P')
        {
            cout << "what size popcorn would you like (type s for small, m for medium, l for large or j for jumbo) and how many (type a single number)?" << endl;
            cin >> Psize >> how_many;
            if (Psize = 's')
            {
                TOTALp = sp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }
            else if (Psize = 'm')
            {
                TOTALp = mp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }
            else if (Psize = 'l')
            {
                TOTALp = lp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }
            else if (Psize = 'j')
            {
                TOTALp = jp*how_many;
                cout << "Okay you total is: " << TOTALp << endl;
            }


            else if (answer = 'S')
            {

                cout << "what size soda would you like (type small, medium, large or jumbo) and how many (type a single number)?" << endl;
                cin >> Ssize >> how_many;
                if (Ssize = 's')
                {
                    TOTALs = ss*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }
                else if (Ssize = 'm')
                {
                    TOTALs = ms*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }
                else if (Ssize = 'l')
                {
                    TOTALs = ls*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }
                else if (Ssize = 'j')
                {
                    TOTALs = js*how_many;
                    cout << "Okay you total is: " << TOTALs << endl;
                }

            }
            cout << "Thanks for buying come again soon." << endl;
        }
    break;
    case 'n':
        cout << "Okay have a great day!" << endl;
    break;
    default:
        cout << "I dont understand...!" << endl;
    break;
    }
    return 0;
}
#包括“stdio.h”
#包括“iostream”
使用名称空间std;
int main()
{
枚举大小{小、中、大、巨型};
大小爆米花大小,饮用;
双sp=1.25,mp=2.25,lp=3.50,jp=4.25,TOTALp,TOTALs,ss=1.50,ms=2.50,ls=3.75,js=4.50;
字符选择,回答,心灵感应,心灵感应;
int多少;
不能选择;
开关(选择)
{
案例“y”:
答不上来;
如果(答案='P')
{
想一想>>有多少人;
如果(Psize='s')
{
TOTALp=sp*多少;

非常感谢!但是,关于爆米花和汽水的大小和价格,我仍然在思考如何在代码中实现枚举数据。问题是,您希望用户输入什么?例如,您可以编写一个switch case语句,接受用户输入并设置每种情况下的枚举值。