我可以知道如何解决我的代码中的错误吗?

时间:2018-04-08 10:01:25

标签: c++

问题:我可以知道如何解决我的代码中出现的错误,查看所有错误并删除客户想要的不需要的waffle而不使用任何链接列表吗?

  

C:\ Users \ Arianna \ Documents \ LABC ++ \ Lab2 \ ASSIGNMENT DSA SEM2 2.cpp in function' void orderForm()':   321 17 C:\ Users \ Arianna \ Documents \ LABC ++ \ Lab2 \ ASSIGNMENT DSA SEM2 2.cpp [错误]' extraFillings'在这方面没有申明   332 41 C:\ Users \ Arianna \ Documents \ LABC ++ \ Lab2 \ ASSIGNMENT DSA SEM2 2.cpp [Error]类型的无效操作数' const char [29]'和''二进制'运算符/'   335 19 C:\ Users \ Arianna \ Documents \ LABC ++ \ Lab2 \ ASSIGNMENT DSA SEM2 2.cpp [Error]' extraToppings'在这方面没有申明   341 15 C:\ Users \ Arianna \ Documents \ LABC ++ \ Lab2 \ ASSIGNMENT DSA SEM2 2.cpp [错误]' taxInvoice'在这方面没有申明   355 1 C:\ Users \ Arianna \ Documents \ LABC ++ \ Lab2 \ ASSIGNMENT DSA SEM2 2.cpp [错误]此处不允许使用函数定义' {'代币   569 11 C:\ Users \ Arianna \ Documents \ LABC ++ \ Lab2 \ ASSIGNMENT DSA SEM2 2.cpp [错误]预期'}'在输入结束时

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

int main()
{
    char choice,options;
    char *tmp,*tmp2;
    int sentinel=0;
    double priceSoft1=10.00,priceCrispy1=12.00,priceSoft2=14.00,priceCrispy2=16.00,priceSoft3=12.00,priceCrispy3=14.00;
    double payment,total;
    double TotalAmt1,TotalAmt2,TotalAmt3,TotalAmt4,TotalAmt5,TotalAmt6;
    double Fillings=1.20,Toppings=1.50;
    double TotalAmount1,TotalAmount2,TotalAmount3,TotalAmount4,TotalAmount5,TotalAmount6;
    char wMenu[100];
    int listOption,orderForm;
    int num1,num2,num3,num4,num5,num6;
}

class waffle 
{
    private:
        struct cashier
        {
            char name [30]; //Name up to 30 letters
            int idNum; //Id Number in Integer
            cashier *next;//Pointer to the next node
        };
        cashier *start_ptr;//Start pointer (root)

    public:

        waffleShop()
                    {
                        start_ptr=NULL;
                    }//Add constructor and initialize start pointer to NULL

            int cashierList();
            void add_new_acc();
            void displayList();
            void delete_start_ptr();
            void delete_end_node();

};


int waffle::cashierList()
{
    char choice,options;

    int listOption=0;

    cout<<"Please choose the option from the list";
    cout<<"<<1>>Add node at the end of the list"<<endl;
    cout<<"<<2>>Display List"<<endl;
    cout<<"<<3>>Delete first"<<endl;
    cout<<"<<4>>Delete last"<<endl;
    cout<<"<<5>>Sign Out"<<endl;
    cin>>listOption;

    switch(listOption)
    {
        case 1:
            add_new_acc();
            break;
        case 2:
            displayList();
            break;
        case 3:
            delete_start_ptr();
            break;
        case 4:
            delete_end_node();
            break;
        case 5:
            cout<<"Would you like to sign out?";
            cout<<" \n Press [Y] for Yes, and [N] for No.\n\n\tEnter Choice : ";
            cin >>choice;

        if  ((choice !='N')&&(choice !='n'))
            {

                return cashierList();
            }
        else
            {

                cout<<"You have already sign out from the system";
                system("cls");
            }

        break;
    }
        return 0;
}

void waffle::add_new_acc()
{

    cashier *tmp,*tmp2;//temporary pointers

    tmp=new cashier;
    //Reserve space for the new node to fill in data
    cout<<"Create New Account"<<endl;
    cout<<"Please enter your name:"<<endl;
    cin>>tmp->name;
    cout<<"To create your Cashier ID"<<endl;
    cout<<"Please enter last 4 digit of your Id: "<<endl;
    cin>>tmp->idNum;

    tmp->next=NULL;

    if(start_ptr==NULL)

        start_ptr=tmp;

    else
    {
        tmp2=start_ptr;//The list is not empty since it is not NULL

        while(tmp2->next!=NULL)
        tmp2=tmp2->next;//move to next link 
        tmp2->next=tmp;

    }

        cashierList();
}

void waffle::displayList()
{
    char wMenu[100];

    cashier *tmp;
    tmp=start_ptr;

    while(tmp)
    {
        cout<<"Cashier Name:"<<tmp->name<<endl;
        cout<<"Cashier Id:"<<tmp->idNum<<endl;

        tmp=tmp->next;

    }

    main();
}

void waffle::delete_start_ptr()
{
    cashier *tmp;

    tmp=start_ptr;
    start_ptr=start_ptr->next;
    delete tmp;

    cashierList();
}

void waffle::delete_end_node()
{
    cashier *tmp1,*tmp2;

    if(start_ptr==NULL)

    cout<<"You're not in the list"<<endl;

    else
    {
        tmp1=start_ptr;
        if(tmp1->next==NULL)
        {
            cout<<"You are a New User!!"<<endl;
            delete tmp1;
            start_ptr=NULL;

        }
        else
        {
            while(tmp1->next !=NULL)
            {
                tmp2=tmp1;
                tmp1=tmp1->next;

            }

            delete tmp1;
            tmp2->next=NULL;
        }
    }

    cashierList();
}

void wMenu()
{
    char options;

    cout<<"----------------------------------------------------------------------";
    cout<<"WAFFLE TYPE ! CRISPY(RM) ! SOFT(RM) ! EXTRA CHARGE(RM) !";
    cout<<"----------------------------------------------------------------------";
    cout<<"1)American  ! 12.00      ! 10.00    ! - RM1.20 for additional filling";
    cout<<"2)Belgium   ! 16.00      ! 14.00    ! - RM1.50 additional topping";
    cout<<"3)Rolled    ! 14.00      ! 12.00    !/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t";
    cout<<"----------------------------------------------------------------------";
    cout<<"Options:";
    cout<<"\nFilling-choc,butter,kaya,ice cream,strawberry,blueberry";
    cout<<"\nTopping(except for Rolled Waffle)";
    cout<<"a)ice cream-vanila,chocolate or mix flavour";
    cout<<"b)fruits-banana or strawberry";
    cout<<"----------------------------------------------------------------------";

    cout<<"Would you like proceed your order?"<<endl;
    cin>>options;

    cout<<" \n Press [Y] for Yes, and [N] for No.\n\n\tEnter Options : ";
    if  ((options !='N')&&(options !='n'))
            {

                 main();
            }
        else
            {
                cout<<"Next Customer please ";
                return wMenu();

            }
}
void orderForm()
{
    int order, choiceA,choiceB;
    int num1,num2,num3,num4,num5,num6;
    double AmountSale1,AmountSale2,AmountSale3,AmountSale4,AmountSale5,AmountSale6;
    double priceSoft1=10.00,priceCrispy1=12.00,priceSoft2=14.00,priceCrispy2=16.00,priceSoft3=12.00,priceCrispy3=14.00;


    cout<<"----------------------------------";
    cout<<"(1)Soft American Waffle RM10.00   ";
    cout<<"----------------------------------";
    cout<<"(2)Crispy American Waffle RM12.00 ";
    cout<<"----------------------------------";
    cout<<"(3)Soft Belgium Waffle RM14.00    ";
    cout<<"----------------------------------";
    cout<<"(4)Crispy Belgium Waffle RM16.00  ";
    cout<<"----------------------------------";
    cout<<"(5)Soft Rolled Waffle RM12.00     ";
    cout<<"----------------------------------";
    cout<<"(6)Crispy Rolled Waffle RM14.00   ";
    cout<<"----------------------------------";

    while(order!=0)
    {
    do
    {   
    cout<<"\nFrom the waffle menu , what would you like : ";
    cin>>order;
    }
    while(1<order<5);
    switch(order)
    {
        case 1:
            cout<<"How many soft American waffle would you like:";
            cin>>num1;

            AmountSale1=priceSoft1*num1;

            break;

        case 2:
            cout<<"How many crispy American waffle would you like:";
            cin>>num2;

            AmountSale2=priceCrispy1*num2;

            break;

        case 3:
            cout<<"How many soft Belgium waffle would you like: ";
            cin>>num3;

            AmountSale3=priceSoft2*num3;

            break;

        case 4:
            cout<<"How many crispy Belgium waffle would you like: ";
            cin>>num4;  

            AmountSale4=priceCrispy2*num4;

            break;

        case 5:
            cout<<"How many soft Rolled waffle would you like :";
            cin>>num5;

            AmountSale5=priceSoft3*num5;

            break;

        case 6:
            cout<<"How many crispy Rolled waffle would you like :";
            cin>>num6;

            AmountSale6=priceCrispy3*num6;

            break;

        default:cout<<"Please choose a valid order from the menu\n";

    }


    cout<<" Do you want to add fillings? ";
    cout<<" \n Press [Y] for Yes, and [N] for No.\n\n\tEnter Choice : ";
    cin >> choiceA;

     if ((choiceA ='Y')&&(choiceA !='N')&&(choiceA ='y')&&(choiceA !='n'))
    {

        extraFillings();

    }
    else
    {
        cout<<"Would you like to add Topings?";
        cout<<" \n Press [Y] for Yes, and [N] for No.\n\n\tEnter Choice : ";
        cin>>choiceB;

        if((choiceB ='Y')&&(choiceB !='N')&&(choiceB ='y')&&(choiceB !='n'))
        {
            cout<<"Topping(except ROLLED WAFFLE"/endl;
            if(order!=5&&order!=6) 
            {
                extraToppings();
            }

            else
            {

            taxInvoice();


            }

        }


    }

}


void extraFillings()
{
    int typeofFillings,

    cout<<"----------------------------------";
    cout<<"(1)Soft American Waffle RM10.00   ";
    cout<<"----------------------------------";
    cout<<"(2)Crispy American Waffle RM12.00 ";
    cout<<"----------------------------------";
    cout<<"(3)Soft Belgium Waffle RM14.00    ";
    cout<<"----------------------------------";
    cout<<"(4)Crispy Belgium Waffle RM16.00  ";
    cout<<"----------------------------------";
    cout<<"(5)Soft Rolled Waffle RM12.00     ";
    cout<<"----------------------------------";
    cout<<"(6)Crispy Rolled Waffle RM14.00   ";
    cout<<"----------------------------------";

    cout<<"Waffle Added with Filings RM1.20 will be charged"


    cout<<"Remark:    ";
    cin>>typeofFillings;

switch(order)
{
    case 1:
        TotalAmt1=AmountSale1+Fillings;

        break;

    case 2:
        TotalAmt2=AmountSale2+Fillings;

        break;  

    case 3:
        TotalAmt3=AmountSale3+Fillings;

        break;

    case 4:
        TotalAmt4=AmountSale4+Fillings;

        break;

    case 5:
        TotalAmt5=AmountSale5+Fillings;

        break;

    case 6:
        TotalAmt6=AmountSale6+Fillings;

        break;

    default:cout<<"Please choose a valid order from the menu\n";
}

    extraTopings(void);
}

void extraTopings()
{
    cout<<"----------------------------------";
    cout<<"(1)Soft American Waffle RM10.00   ";
    cout<<"----------------------------------";
    cout<<"(2)Crispy American Waffle RM12.00 ";
    cout<<"----------------------------------";
    cout<<"(3)Soft Belgium Waffle RM14.00    ";
    cout<<"----------------------------------";
    cout<<"(4)Crispy Belgium Waffle RM16.00  ";
    cout<<"----------------------------------";

    cout<<"*****TOPPINGS OF ROLLED WAFFLE IS INVALID*****";
    cout<<"Remark:    ";
    cin>>typeofTopings;

    switch(order)
{
    case 1:
        TotalAmount1=AmountSale1+Toppings;

        break;

    case 2:
        TotalAmount2=AmountSale2+Toppings;

        break;  

    case 3:
        TotalAmount3=AmountSale3+Toppings;

        break;

    case 4:
        TotalAmount4=AmountSale4+Toppings;

        break;

    default:cout<<"Please choose a valid order from the menu\n";
}

    taxInvoice();
}

void taxInvoice();
{
    int  ans,select;
    double payment;
    cout<<"----------------------------------";
    cout<<"(1)     Normal Waffle             ";
    cout<<"----------------------------------";
    cout<<"(2)     Waffle with Fillings      ";
    cout<<"----------------------------------";
    cout<<"(3)     Waffle with Toppings      ";
    cout<<"----------------------------------";


    cout<<" You have ordered:\n\n";
    cout<<"Select the selection  ";
    cin>>select;
    if(select==1)
    {
     cout<<"NORMAL"/endl;

     cout<<" ITEM\t\t\t\tQUANTITY\tUNIT PRICE\tAMOUNT OF SALE\n";

     cout<<" Soft American Waffle:\t\t\t"<<num1<<"\t\tRM   "<<priceSoft1<<"\tRM   "<<AmountofSale1<<"\n";
     cout<<" Crispy American Waffle:\t\t"<<num2<<"\t\tRM   "<<priceCrispy1<<"\tRM "<<AmountofSale2<<"\n";
     cout<<" Soft Belgium Waffle:\t"     <<num3<<"\t\tRM   "<<priceSoft2<<"\tRM   "<<AmountofSale3<<"\n";
     cout<<" Crispy Belgium Waffle:\t\t" <<num4<<"\t\tRM   "<<priceCrispy2<<"\tRM "<<AmountofSale4<<"\n";
     cout<<" Soft Rolled Waffle:\t\t\t"  <<num5<<"\t\tRM   "<<priceSoft3<<"\tRM   "<<AmountofSale5<<"\n";
     cout<<" Crispy Rolled Waffle:\t\t\t"<<num6<<"\t\tRM   "<<priceCrispy3<<"\tRM "<<AmountofSale6<<"\n";

    total=0;
    total=total+AmountofSale1+AmountofSale2+AmountofSale3+AmountofSale4+AmountofSale5+AmountofSale6;

    }
    else
    {
        if(select==2)
        {


            cout<<"With Fillings"/endl;

            cout<<" ITEM\t\t\t\tQUANTITY\tUNIT PRICE\tAMOUNT OF SALE\n";

            cout<<" Soft American Waffle:\t\t\t"<<num1<<"\t\tRM   "<<priceSoft1<<"\tRM   "<<TotalAmt1<<"\n";
            cout<<" Crispy American Waffle:\t\t"<<num2<<"\t\tRM   "<<priceCrispy1<<"\tRM "<<TotalAmt2<<"\n";
            cout<<" Soft Belgium Waffle:\t"     <<num3<<"\t\tRM   "<<priceSoft2<<"\tRM   "<<TotalAmt3<<"\n";
            cout<<" Crispy Belgium Waffle:\t\t" <<num4<<"\t\tRM   "<<priceCrispy2<<"\tRM "<<TotalAmt4<<"\n";
            cout<<" Soft Rolled Waffle:\t\t\t"  <<num5<<"\t\tRM   "<<priceSoft3<<"\tRM   "<<TotalAmt5<<"\n";
            cout<<" Crispy Rolled Waffle:\t\t\t"<<num6<<"\t\tRM   "<<priceCrispy3<<"\tRM "<<TotalAmt6<<"\n";

            total=0;
            total=total+TotalAmt1+TotalAmt2+TotalAmt3+TotalAmt4+TotalAmt5+TotalAmt6;

        }
        else
        {
            if(select==3)
            {
                cout<<"With Toppings"/endl;

                cout<<" Soft American Waffle:\t\t\t"<<num1<<"\t\tRM   "<<priceSoft1<<"\tRM   "<<TotalAmount1<<"\n";
                cout<<" Crispy American Waffle:\t\t"<<num2<<"\t\tRM   "<<priceCrispy1<<"\tRM "<<TotalAmount2<<"\n";
                cout<<" Soft Belgium Waffle:\t     "<<num3<<"\t\tRM   "<<priceSoft2<<"\tRM   "<<TotalAmount3<<"\n";
                cout<<" Crispy Belgium Waffle:\t\t "<<num4<<"\t\tRM   "<<priceCrispy2<<"\tRM "<<TotalAmount4<<"\n";
                cout<<" Soft Rolled Waffle:\t\t\t  "<<num5<<"\t\tRM   "<<priceSoft3<<"\tRM   "<<TotalAmount5<<"\n";
                cout<<" Crispy Rolled Waffle:\t\t\t"<<num6<<"\t\tRM   "<<priceCrispy3<<"\tRM "<<TotalAmount6<<"\n";

                total=0;
                total=total+TotalAmount1+TotalAmount2+TotalAmount3+TotalAmount4+TotalAmount5+TotalAmount6;

            }

        }
    }
    cout<<"\t\t\t\t\t\tThat would be:  RM "<<total<<"\n";

        cout<<"Order Again[0]no[1]yes"
        cin<<ans;
        if(ans==0)
        {
            if(payment<total)
            {
                cout<<"Insufficient Money";
            }
            else
            {
                cout<<"\n\tEnter Received Cash : ";
                cin >> payment;

                if(payment>total)
                {
                    change=payment-total;
                    cout<<"\tYour change is:"<<change<<"\n\n\n\n\t\t"
                }
            }


                do
                {
                cout<<" New transaction [0] no [1] yes : ";
                cin >> ans;
                } while ((ans != 0)&&(ans != 1));
        }
                system("cls\n\n\n\t\t");
                system("PAUSE");

        return 0;

}

1 个答案:

答案 0 :(得分:0)

错误“函数X未在此范围内声明”是因为您调用的函数是在文件中调用它之后声明的函数。在编译时,编译器无法知道它是什么。 例如:orderForm调用extraFillings它尚未定义,因为它稍后在文件中定义。 您需要创建一个包含函数原型的头文件并将其链接到您的项目,或者您需要确保在调用者之前声明您调用的函数。