| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 384 人关注过本帖
标题:输入数字想得到算时结果输不出来
只看楼主 加入收藏
阿盼
Rank: 1
等 级:新手上路
帖 子:21
专家分:4
注 册:2015-4-19
结帖率:88.89%
收藏
已结贴  问题点数:17 回复次数:3 
输入数字想得到算时结果输不出来
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <iostream.h>
#include <conio.h>
int yiwei(int m,int n,int k);
int liangwei(int m,int n,int k);
int sanwei(int m,int n,int k);
void main()
{
   int score,m,n,k,choose;
   printf("========================\n");
   printf("请选择下面的一个项目:\n");     /*显示主菜单*/
   printf("   \t1.一位数\n");
   printf("   \t2.二位数\n");
   printf("   \t3.三位数\n");
   printf("   \t4.退出\n");
   printf("========================\n");
   printf("请选择1~4:\n");                            在这一步输入数字怎么得不到算式呀???????
   choose=getch();                 /*输入所选的数字*/
   switch(choose)
   {
     case 1:yiwei(m,n,k);break;        /* 调用自定义函数yiwei*/
     case 2:liangwei(m,n,k);break;       /*调用自定义函数liangwei*/
     case 3:sanwei(m,n,k);break;         /*调用自定义函数sanwei*/
     case 4:exit(0);break;              /*退出*/
          default:  break;
         
   }
 
   
}
int yiwei(int m,int n,int k)            /*定义函数yiwei*/
{
     int  i,a1,a2,a3,s,result,score;
     char flag[3]={'+','-','*'};
   
     srand(time(NULL));           /*随机种子初始化*/
     for(i=1;i<=10;i++)
     {
       a1=rand()%10;              /*随机生成一位数a1,a2*/
       a2=rand()%10;
       a3=rand()%2 ;             /*生成0到2之间的数k*/
       switch(k)                 
                                 
       {
          case 0:printf("%d %c %d",a1,flag[a3],a2);   /*转换成算式*/
              result=a1+a2;
              break;
          case 1:printf("%d %c %d",a1,flag[a3],a2);
              result=a1-a2;
              break;
          case 2:printf("%d %c %d",a1,flag[a3],a2);
              result=a1*a2;
              break;
         default:  
            printf("somethingis wrong!\n");   
            break;
       }
     }
        scanf("%d", &s);                           /*输入答案*/
        if(s == result)                             /*第一次判断正确加十分*/
        {  
            score+= 10;  
            printf("完全正确,你非常聪明!加10分\n");
      
        }
        else                                    
        {
            printf("你答错了,继续努力!\n");
            printf("%d %c% d=",a1,flag[a3],a2);         /*错重新输出*/  
            scanf("%d",&s);
            if(s==result)                              /*第二次判断正确加8分*/
            {
                score+=8;
                printf("答对了,你很棒!加8分\n");
            }
            else
            {
                printf("你答错了,继续努力!\n");
                printf("%d %c% d=",a1,flag[a3],a2);       /*错重新输出*/  
                  scanf("%d",&s);
                if(s==result)                            /*第三次判断正确加6分*/
                {
                   score+=6;            
                   printf("答对了,祝贺你!加6分\n");
                }
                else                                     /*错输出正确结果并进行下一题*/
                    printf("非常遗憾你又答错了,请继续做下一题。本题的正确答案为%d\n",s);
            }
        }
        return score;
   
            

}
int liangwei(int m,int n,int k)            /*定义函数liangwei*/
{
     int  i,a1,a2,a3,s,result,score;
     char flag[4]={'+','-','*','/'};
     srand(time(NULL));           /*随机种子初始化*/
     for(i=1;i<=10;i++)
     {
       a1=rand()%10;              /*随机生成一位数a1,a2*/
       a2=rand()%10;
       a3=rand()%3 ;             /*生成0到3之间的数k*/
       switch(k)                 
                                 
       {
          case 0:printf("%d %c %d",a1,flag[a3],a2);   /*转换成算式*/
              result=a1+a2;
              break;
          case 1:printf("%d %c %d",a1,flag[a3],a2);
              result=a1-a2;
              break;
          case 2:printf("%d %c %d",a1,flag[a3],a2);
              result=a1*a2;
          case 3:printf("%d %c%d",a1,flag[a3],a2);
              break;
         default:  
            printf("somethingis wrong!\n");   
            break;
       }
     }
        scanf("%d", &s);                           /*输入答案*/
        if(s == result)                             /*第一次判断正确加十分*/
        {  
            score+= 10;  
            printf("完全正确,你非常聪明!加10分\n");
      
        }
        else                                    
        {
            printf("你答错了,继续努力!\n");
            printf("%d %c% d=",a1,flag[a3],a2);         /*错重新输出*/  
            scanf("%d",&s);
            if(s==result)                              /*第二次判断正确加8分*/
            {
                score+=8;
                printf("答对了,你很棒!加8分\n");
            }
            else
            {
                printf("你答错了,继续努力!\n");
                printf("%d %c% d=",a1,flag[a3],a2);       /*错重新输出*/  
                  scanf("%d",&s);
                if(s==result)                            /*第三次判断正确加6分*/
                {
                   score+=6;            
                   printf("答对了,祝贺你!加6分\n");
                }
                else                                     /*错输出正确结果并进行下一题*/
                    printf("非常遗憾你又答错了,请继续做下一题。本题的正确答案为%d\n",s);
            }
        }

   
              return score;
      

}
int sanwei(int m,int n,int k)            /*定义函数sanwei*/
{
     int  i,a1,a2,a3,s,result,score;
     char flag[5]={'+','-','*','/','%'};
     srand(time(NULL));           /*随机种子初始化*/
     for(i=1;i<=10;i++)
     {
       a1=rand()%10;              /*随机生成一位数a1,a2*/
       a2=rand()%10;
       a3=rand()%4;             /*生成0到4之间的数k*/
       switch(k)                 
                                 
       {
          case 0:printf("%d %c %d",a1,flag[a3],a2);   /*转换成算式*/
              result=a1+a2;
              break;
          case 1:printf("%d %c %d",a1,flag[a3],a2);
              result=a1-a2;
              break;
          case 2:printf("%d %c %d",a1,flag[a3],a2);
              result=a1*a2;
          case 3:printf("%d %c %d",a1,flag[a3],a2);
              break;
          case 5:printf("%d %c %d",a1,flag[k],a2);
         default:  
            printf("somethingis wrong!\n");   
            break;
       }
     }
        scanf("%d", &s);                           /*输入答案*/
        if(s == result)                             /*第一次判断正确加十分*/
        {  
            score+= 10;  
            printf("完全正确,你非常聪明!加10分\n");
      
        }
        else                                    
        {
            printf("你答错了,继续努力!\n");
            printf("%d %c% d=",a1,flag[a3],a2);         /*错重新输出*/  
            scanf("%d",&s);
            if(s==result)                              /*第二次判断正确加8分*/
            {
                score+=8;
                printf("答对了,你很棒!加8分\n");
            }
            else
            {
                printf("你答错了,继续努力!\n");
                printf("%d %c% d=",a1,flag[a3],a2);       /*错重新输出*/  
                  scanf("%d",&s);
                if(s==result)                            /*第三次判断正确加6分*/
                {
                   score+=6;            
                   printf("答对了,祝贺你!加6分\n");
                }
                else                                     /*错输出正确结果并进行下一题*/
                    printf("非常遗憾你又答错了,请继续做下一题。本题的正确答案为%d\n",s);
            }
        }
            return score;
   
}
搜索更多相关主题的帖子: include 项目 
2015-06-28 11:45
醉祁今朝
Rank: 2
等 级:论坛游民
威 望:1
帖 子:48
专家分:76
注 册:2015-5-18
收藏
得分:4 
建议楼主把自己的程序从头到尾检查一遍,理清楚,问题估计就解决了。

多艰难 都要走下去
2015-06-28 12:21
xy165598994
Rank: 1
等 级:新手上路
帖 子:6
专家分:9
注 册:2015-6-28
收藏
得分:4 
choose=getch();      这句错了
改成choose=getchar();试试
2015-06-28 13:08
lmlm1001
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:4
帖 子:107
专家分:550
注 册:2015-3-1
收藏
得分:4 
choose=getch() - '0';
2015-06-29 00:37
快速回复:输入数字想得到算时结果输不出来
数据加载中...
 
   



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

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