循环不工作?

时间:2015-09-13 15:45:52

标签: c++

在回到主菜单的调用之后,它返回到mainMenu,但是当键入选项或命令时,不接受该选项或循环不起作用。不知道哪里出错了?是应该添加额外的电话还是?

#include <iostream>
using namespace std;
char mainMenu(void);
int factorial(int n);
unsigned long long combination(long nK, long nR);

int main(){
char option;
int shape,function,i,j,k,t,n;
long nK, nR;
unsigned long long COM;

while((option=mainMenu())!='0')
{
    switch(option)
    {
        case '1'://Program 1: 
            cout<< "*Drawing a shape\n"
                << "(1-Rectangle, 2-Triangle, 3-Inverted Triangle, 4-Letter 'H', 0-Back to Main Menu)\n";
            do
            {
                cout<< "Choose shape >> ";
                cin>> shape;
                cout<< endl;

                switch(shape)
                {
                    case 1: break;
                    case 2: break;
                    case 3: break;
                    case 4: break;
                    case 0:
                        //Back to Main Menu
                        cout<< "Back to main menu\n"
                            << endl;
                        return mainMenu();     //After here, it does back to Main Menu but command or option is not working 
                    }
            }while(shape!=0);

        case '2': //Program 2
            cout<< "*Choose function of calculator\n"
                << "(1-Factorial, 2-Combination, 0-Back to main menu)\n";
            do
            {
                cout<< "Choose function >> ";
                cin>> function;
                cout<< endl;

                switch(function)
                {
                    case 1: break;
                    case 2: break;
                    case 0:
                        cout<< "Back to main menu\n"
                            << endl;
                        return mainMenu();
                }
            }while(function!=0);
        case '0':
            cout<< "Program is terminating\n"
                << endl;
            return 0;
        default:
            cout<< "Wrong input. Please choose one of the above options.\n"
                << endl;
            return mainMenu();
    }
}
}

char mainMenu(void){
char option;
cout<< "##############################\n"
    << "Main Menu\n"
    << "Enter your command!\n"
    << "##############################\n"
    << endl
    << "1. Program1\n"
    << "2. Program2\n"
    << "0. Exit\n"
    << endl
    << "Command >> ";
cin>> option;
cout<< endl;
return option;
}

0 个答案:

没有答案