main 函数

1 main函数 中的内容不宜过多。

2 当想在main函数中使用while时候,可以这样做:

int main()

{
while(function1)    //此处的while的循环体是一个空语句。

}

function1()

{

。。。

 

return 1;

}

//------------------------example------------------

#include<iostream>
using namespace std;

/*
print star
*/
int MainMenu();

int main() {
    //srand(unsigned(time(0)));
    while (MainMenu());

}
int MainMenu() {
    system("cls");
    cout << "1 我想你猜" << endl;
    cout << "2 你想我猜" << endl;
    cout << "3 排行榜" << endl;
    cout << "0 退出" << endl;

    int choice;
    cout << "please input your choose:" << endl;
    cin >> choice;
    switch (choice)
    {
    case 1:
        break;
    case 2:
        break;
    case 3:
        break;
    case 0:
        return 0;
    default:
        cout << "input error!\tplease input again" << endl;
        system("pause");
        break;

    }
    return 1;
}

posted @ 2022-07-06 08:59  江南王小帅  阅读(313)  评论(0)    收藏  举报