| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2203 人关注过本帖
标题:一个四则运算小游戏的程序,请各位大神看看是哪写错了
取消只看楼主 加入收藏
SillyLou
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-5-26
收藏
 问题点数:0 回复次数:0 
一个四则运算小游戏的程序,请各位大神看看是哪写错了
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void plus();
void minus();
void times();
void divide();
int config(int ans,int rit);
int main(void)
{
    int i;
    for(;;)
    {system("cls");
        printf("\n   calculation game\n");
        printf("**********************\n");
        printf("1.plus calculation\n");
        printf("2.minus calculation\n");
        printf("3.times calculation\n");
        printf("4.division calculation\n");
        printf("0.exit\n");
        printf("**********************\n");
        fflush(stdin);//trying
        scanf("%d",&i);
        switch(i){
        case 1:plus();break;
        case 2:minus();break;
        case 3:times();break;
        case 4:divide();break;
        case 0:exit(0);break;}
    }
    return 0;
}
    void plus()
    {
        int i=-1,seed,a,b,c,ans;char n;
        for(;i==0;)
        {seed=time(0);system("cls");
        printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");fflush(stdin);
            scanf("%d",&i);
            if(i==1)
            {
                srand(seed);
                for(;;){    a=rand()%10;b=rand()%10;
                c=a+b;
                printf("\n%d+%d=",a,b);fflush(stdin);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
            else if(i==2)
            {
                srand(seed);
                for(;;){    a=rand()%100;b=rand()%100;
                c=a+b;
                printf("\n%d+%d=",a,b);fflush(stdin);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
        }
END:printf("\npress any key to continue\n");getchar();
    }
    void minus()
    {
        int i=-1,seed,a,b,c,ans;char n;
        for(;i==0;)
        {seed=time(0);system("cls");
        printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");
            scanf("%d",&i);
            if(i==1)
            {
                srand(seed);
                for(;;){    a=rand()%10;b=rand()%10;if(a<b){c=a;a=b;b=c;}
                c=a-b;
                printf("\n%d-%d=",a,b);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
            else if(i==2)
            {
                srand(seed);
                for(;;){    a=rand()%100;b=rand()%100;if(a<b){c=a;a=b;b=c;}
                c=a-b;
                printf("\n%d-%d=",a,b);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
        }
END:printf("\npress any key to continue\n");getchar();
    }
    void divide()
    {
        int i=-1,seed,a,b,c,ans;char n;
        for(;i==0;)
        {seed=time(0);system("cls");
        printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");
            scanf("%d",&i);
            if(i==1)
            {
                srand(seed);
                for(;;){    a=rand()%10;b=rand()%10;if(a<b){c=a;a=b;b=c;}if(a%b)a-=a%b;
                c=a/b;
                printf("\n%d/%d=",a,b);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
            else if(i==2)
            {
                srand(seed);
                for(;;){    a=rand()%100;b=rand()%100;if(a<b){c=a;a=b;b=c;}if(a%b)a-=a%b;
                c=a/b;
                printf("\n%d/%d=",a,b);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
        }
END:printf("\npress any key to continue\n");getchar();
    }
    void times()
    {
        int i=-1,seed,a,b,c,ans;char n;
        for(;i==0;)
        {seed=time(0);system("cls");
        printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");
            scanf("%d",&i);
            if(i==1)
            {
                srand(seed);
                for(;;){    a=rand()%10;b=rand()%10;
                c=a*b;
                printf("\n%d*%d=",a,b);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
            else if(i==2)
            {
                srand(seed);
                for(;;){    a=rand()%100;b=rand()%100;
                c=a*b;
                printf("\n%d*%d=",a,b);
                scanf("%d",&ans);
                if(config(ans,c))printf("\nyou're right\n");
                else printf("you're wrong\n");
                printf("would you like to continue? (Y/N)\n");
                while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
                }
            }
        }
END:printf("\npress any key to continue\n");getchar();
    }
    int config(int ans,int rit)
    {
        return ans==rit?1:0;
    }

plus()等四个函数的for循环好像没运行,然后直接就跳出了……各位大神求指教啊
搜索更多相关主题的帖子: include 小游戏 system 
2016-07-08 00:04
快速回复:一个四则运算小游戏的程序,请各位大神看看是哪写错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057122 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved