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 @   江南王小帅  阅读(307)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2021-07-06 指向指针的指针变量
2021-07-06 获取数组长度的两种方法
2021-07-06 不同类型数组对应输出
2021-07-06 字符型数组和指针变量
2021-07-06 指针的运算
2021-07-06 利用下标变量显示数组a&利用指针变量显示数组a
点击右上角即可分享
微信分享提示