| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1220 人关注过本帖
标题:错误出在那里啊!
只看楼主 加入收藏
kennyhip
该用户已被删除
收藏
已结贴  问题点数:20 回复次数:13 
错误出在那里啊!
提示: 作者被禁止或删除 内容自动屏蔽
搜索更多相关主题的帖子: first void character include second 
2010-05-22 01:01
shuishenxian
Rank: 2
来 自:河南新乡
等 级:论坛游民
帖 子:40
专家分:64
注 册:2010-5-16
收藏
得分:4 
#include<stdio.h>

int main(void)
{
  int  num1, demon1,num2,demon2,result_num,result_demon,b;
  int a;

  printf("Enter first fraction: ");
  scanf("%d/%d",&num1,&demon1);

  printf("Enter second fraction: ");
  scanf("%d/%d",&num2,&demon2);
  printf("'+'=1\n");
  printf("'-'=2\n");
  printf("'*'=3\n");
  printf("'/'=4\n");
  printf("Enter a digital: ");
  scanf("%d",&a);

  switch(a)
    {
  case 1 : result_num=num1*demon2+num2*demon1;
            result_demon=demon1*demon2;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
  case 2: result_num=num1*demon2-num2*demon1;
            result_demon=demon1*demon2;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
  case 3 : result_num=num1*num2;
            result_demon=demon1*demon2;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
  case 4: result_num=num1*demon2;
            result_demon=num2*demon1;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
       default: printf("ERROR!\n");
               break;
     }

      return 0;
}
2010-05-22 02:00
luochengwww
Rank: 2
等 级:论坛游民
帖 子:40
专家分:48
注 册:2010-3-31
收藏
得分:1 
int a;                      + - * / 为字符型的  而不是INT型
scanf("%d",&a);         
2010-05-22 05:25
冥卫
Rank: 8Rank: 8
来 自:深山老林
等 级:蝙蝠侠
帖 子:280
专家分:772
注 册:2010-4-20
收藏
得分:0 
来看看
2010-05-22 07:48
youyong407
Rank: 1
等 级:新手上路
帖 子:62
专家分:3
注 册:2008-9-22
收藏
得分:3 
你看看是这个样子吗?
#include<stdio.h>

int main(void)
{
    int  num1, demon1,num2,demon2,result_num,result_demon;
    char a;
   
    printf("Enter first fraction: ");
    scanf("%d/%d",&num1,&demon1);
   
    printf("Enter second fraction: ");
    scanf("%d/%d",&num2,&demon2);
   
    printf("Enter a character(+,-,*,/): ");
    getchar();
    scanf("%c",&a);
   
    switch(a)
    {
    case '+': result_num=num1*demon2+num2*demon1;
        result_demon=demon1*demon2;
        printf("The sum is %d/%d\n",result_num,result_demon);
        break;
    case '-': result_num=num1*demon2-num2*demon1;
        result_demon=demon1*demon2;
        printf("The sum is %d/%d\n",result_num,result_demon);
        break;
    case '*': result_num=num1*num2;
        result_demon=demon1*demon2;
        printf("The sum is %d/%d\n",result_num,result_demon);
        break;
    case '/': result_num=num1*demon2;
        result_demon=num2*demon1;
        printf("The sum is %d/%d\n",result_num,result_demon);
        break;
    default: printf("ERROR!\n");
        break;
    }
   
    return 0;
}

努力!加油!坚持!
2010-05-22 09:43
kennyhip
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2010-05-22 13:13
antonio111
Rank: 2
等 级:论坛游民
帖 子:9
专家分:14
注 册:2010-5-9
收藏
得分:2 
...你的a定义的是int型,5楼那个是char型,OK?
getchar是char型独有的输入语句,它的执行效率比scanf("%c",&a);要高很多,因为scanf是一个函数,必须要调用它,而getchar不是函数.
2010-05-22 13:21
lylovedy123
Rank: 1
等 级:新手上路
帖 子:22
专家分:6
注 册:2010-5-15
收藏
得分:0 
请问一下哦```

``为什么 %d/%d  ???  %d再输出%d 吗`?

 为什么不能直接是%d%d呢`?
2010-05-22 14:50
kinwyb
Rank: 4
等 级:业余侠客
帖 子:134
专家分:244
注 册:2009-3-7
收藏
得分:0 
#include<Stdio.h>
main()
{
  int  num1, demon1,num2,demon2,result_num,result_demon;
  char a;

  printf("Enter first fraction: ");
  scanf("%d/%d",&num1,&demon1);

  printf("Enter second fraction: ");
  scanf("%d/%d",&num2,&demon2);

  printf("Enter a character(+,-,*,/): ");
  scanf("%s",&a);

  switch(a)
    {
  case '+': result_num=num1*demon2+num2*demon1;
            result_demon=demon1*demon2;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
  case '-': result_num=num1*demon2-num2*demon1;
            result_demon=demon1*demon2;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
  case '*': result_num=num1*num2;
            result_demon=demon1*demon2;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
  case '/': result_num=num1*demon2;
            result_demon=num2*demon1;
            printf("The sum is %d/%d\n",result_num,result_demon);
            break;
       default: printf("ERROR!\n");
               break;
     }
}

学习c语言痛苦!!但是要坚持~~
2010-05-22 15:03
kinwyb
Rank: 4
等 级:业余侠客
帖 子:134
专家分:244
注 册:2009-3-7
收藏
得分:0 
回复 8楼 lylovedy123
有2个数所以用 %d/%d 用 / 把2个数分开。。。看的明白。。要是直接 %d%d 就分不出来了,比如输出 2 和 63 用 %d/%d 输出是 2/63 要是直接用 %d%d 输出的话变成 263 理解就有歧义了。你可以理解成 2/63 也可以理解成 26/3 .......

[ 本帖最后由 kinwyb 于 2010-5-22 15:12 编辑 ]

学习c语言痛苦!!但是要坚持~~
2010-05-22 15:10
快速回复:错误出在那里啊!
数据加载中...
 
   



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

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