如果执行if-else语句,如何从int返回到int main?

时间:2018-11-23 05:58:20

标签: c++ if-statement return-value void sales

在执行if-else语句后,如何从int返回到int main?

using namespace std;
    char menu;
    int i,q[10],rot,t[5];
    int pu[10],qu[10];
    int item[10];
    int prodq;
    int num;
    float bank, TS, p[10];
    string prodname[10]; 

所以这个想法是用户必须输入1-5的数字,我试图通过hmmm来实现。分别检测1-5的数字

    int additems () {
        system ("cls");
        slots:

        cout << "SLOT 1: " << prodname[1] << "| x" << q[1] << " | " <<  p[1] << " PHP\n";
        cout << "SLOT 2: " << prodname[2] << "| x" << q[2] << " | " <<  p[2] << " PHP\n";
    cout << "Select slot to manage (1-5): ";
    cin >> num;         


    if(num>6 || num<0){
        system ("cls");
        cout << "Invalid number, please enter numbers exclusively from 1-5 \n";
        goto slots;
    } 

    //INSERT & UPDATE! this section will allow the program to detect if a slot has been used before.


     //switch(menu){
          //case '1' :
          else if(num==1){
            system ("cls");
            cout << "SLOT 1: " << prodname[1] << "| x" << q[1] << " | " <<  p[1] << " PHP\n";
            cout <<"Enter product name for item slot NO.1: ";
            cin >> prodname[1];
            cout <<"Enter quantity of " << prodname[1] << " : ";
            cin >> q[1];
            cout <<"Enter price " << prodname[1] << " : ";
            cin >> p[1];
            system ("cls");
            goto slots;
            return 0;
        }

主要问题:好的,我可以在此if-else语句后成功插入一些信息,在返回int main()之后,我想发生什么?或最终导致mainmenu();。

但是这是在控制台之后发生的事情,它只是说进程在xx秒后退出,返回值为0,我的意图是 让它返回mainmenu();如果它能奇迹般地工作,它只会回到插槽;

            // break;
         // case '2' :
         else if(num==2){

            system ("cls");
            cout << "SLOT 2: " << prodname[2] << "| x" << q[2] << " | " <<  p[2] << " PHP\n";
            cout <<"Enter product name for item slot NO.2: ";
            cin >> prodname[2];
            cout <<"Enter quantity of " << prodname[2] << " : ";
            cin >> q[2];
            cout <<"Enter price " << prodname[2] << " : ";
            cin >> p[2];
            return 0;
       }

       else if(num==3){

         // case'3' :

            system ("cls");
            cout << "SLOT 3: " << prodname[3] << "| x" << q[3] << " | " <<  p[3] << " PHP\n";
            cout <<"Enter product name for item slot NO.3: ";
            cin >> prodname[3];
            cout <<"Enter quantity of " << prodname[3] << " : ";
            cin >> q[3];
            cout <<"Enter price " << prodname[3] << " : ";
            cin >> p[3];
            return 0;
          //   break;
          }
         // case '4' :
         else if(num==4){
     cout <<"empty";
    }

        else if(num==5){

        //  case '5' :
             cout <<"empty";

        /*else if(num==x){

        //  case '5' :
        cout <<"empty";
        //  break;
        */

        return 0;
    }


    }




    int mainmenu(){
        mainmenu:
        { 
            cout << "INVENTORY SYSTEM";
            //I've put some choices here
       cin >> menu;
        }
       switch(menu){
        case '1' :
             system ("cls");
             additems();
             break;
        case '2' :
            system ("cls");
             //placeholder();
       }
        system("cls");


    }



    int main() {

        int choice;
        int choice2;
        int total;
        int itemq;
        char ch;
        int ln;
        int un;
        int l=0;
        int counter=1;

        cout << "L O A D I N G \n\n";

      for (l=0; l<60; l++) { 
      system("Color 0b");
        Sleep(counter);  
        cout << ". "; 
        Sleep(counter);  
      system("Color 0c");
      } 
        //ca

        mainmenu();

0 个答案:

没有答案