| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2228 人关注过本帖
标题:一个四则运算小游戏的程序,请各位大神看看是哪写错了
只看楼主 加入收藏
SillyLou
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-5-26
收藏
 问题点数:0 回复次数:4 
一个四则运算小游戏的程序,请各位大神看看是哪写错了
#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
lanke711
Rank: 9Rank: 9Rank: 9
来 自:流浪在天国之路
等 级:蜘蛛侠
威 望:7
帖 子:317
专家分:1437
注 册:2015-7-16
收藏
得分:0 
   int i=-1,seed,a,b,c,ans;char n;
        for(;i==0;)


初始化i=-1  然而你在for判断中,第二个表达式是i==0成立时,才执行循环语句.
i在初始化之后,就没有改变它的值,递增或者赋值,它还是-1.
这样,i!=0了。所以不会执行循环。

普通人之所以普通,是因为他们普遍有一个通病,那就是认为自己永远普通。
千夫所指,我亦坚持。就算被所有人误解,我也照样守护这一切。
我们总是觉得,这些灵魂的表情,傲慢自大,目中无人,其实,真正目中无人的是我们。它们傲慢的不过是表情,而我们傲慢的却是行为!
记得,是为了忘记!
只要想着有那么一天,我就能忍受现在的每一天!
灾难并不可怕,可怕的是心中没有了希望。
你以为我在天堂,其实我正在路上。
当你觉得自己走不到终点的时候,请不要放弃。或许你的对手也是这种感觉。
2016-07-08 02:09
wanglianyi1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:647
专家分:2067
注 册:2015-6-18
收藏
得分:0 
goto那么多。标识都是END..确定这么跳转不会有问题么,楼主。。你能看出来哪里跳到哪里么。。
2016-07-08 08:48
低调低调
Rank: 3Rank: 3
来 自:四川省成都市
等 级:论坛游侠
威 望:1
帖 子:66
专家分:103
注 册:2016-6-23
收藏
得分:0 
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(int argc, char const *argv[])
{
  
     int n,i,f,g=0,k=0,p=0,o=0,z=0;float b[100],jg;
     char a[100],c[100];
     gets(a);
     n=strlen(a);
     for(i=0;i<n;i++)
     {  if(a[i]<=47)
        {
          c[z++]=a[i];
          f=i-1;
          f=f-g;
          g=i+1;
        while(f>-1)
        {
          jg+=(a[i-(++o)]-48)*pow(10,p++);
          f--;
        }
          b[k]=jg;
          k++;
          jg=0;
          p=0;
          o=0;
        }
        
        else if(i==n-1)
        {
               
          f=i-g;
   
          while(f>-1)
          {
            jg+=(a[i-(o++)]-48)*pow(10,p++);
            f--;
          }
          b[k]=jg;
        }
     }
     jg=0;
     o=k;
     c[z]='\0';
     
     
     for(i=0;i<z;i++)
    {
      if(c[i]=='*')
      {
           b[i+1]=b[i]*b[i+1];
           b[i]=0;
      }
      else if(c[i]=='/')
      {
            b[i+1]=b[i]/b[i+1];
            b[i]=0;
      }
  }
  
    for(i=0;i<z;i++)
      { if(b[0]==0){
          while(b[i]==0)
          i++;
      }
      else if(b[i]==0)c[i]=c[i-1];
         
          if(c[i]=='-')
           {
                 b[i+1]=b[i]-b[i+1];
                 b[i]=0;
           }
      }
      
      for(i=0;i<=z;i++)
        jg+=b[i];
      
      printf("%.2f",jg);

      return 0;
   
 }

可以借鉴思考下,这个代码 ,希望你能有所收获  你那个格式太老火了 我看不懂!  实在不好意思
2016-07-08 20:11
天书
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-7-27
收藏
得分:0 
fegvw
2019-07-27 09:57
快速回复:一个四则运算小游戏的程序,请各位大神看看是哪写错了
数据加载中...
 
   



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

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