| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1988 人关注过本帖
标题:我是名新手,下列程序哪里错误如何纠正,请大神赐教
只看楼主 加入收藏
x1921171331
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2020-4-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:6 
我是名新手,下列程序哪里错误如何纠正,请大神赐教
#include <stdio.h>
void main()
{
    float num1,num2,result;
    char operate;

    printf("Please enter operator:");
    scanf("c",&operate);
    printf("Please enter two numbers:");
    scanf("%f,%f",&num1,&num2);

    switch (operate)
    {
      case'+':
      result=num1+num2;
      printf("%5.2f+%5.2f=%5.2f",num1,num2,result);
      break;

      case'-':
      result=num1-num2;
      printf("%5.2f-%5.2f=%5.2f",num1,num2,result);
      break;

      case'*':
      result=num1*num2;
      printf("%5.2f*5.2f=%5.2f",num1,num2,result);
      break;

      case'/'
      if (num!=o)
      {
          result=num1/num2;
          printf("%5.2f/%5.2f=%5.2f",numi,num2.result);
      }
      else
          printf("In a division operation, the divisor can not be zero);
      break;

      default:
      printf("The operator is invalid");
    }

}
   
搜索更多相关主题的帖子: break printf result case 错误 
2020-04-07 18:02
叶纤
Rank: 8Rank: 8
等 级:禁止访问
威 望:1
帖 子:658
专家分:848
注 册:2019-11-22
收藏
得分:7 
程序代码:
7 8处错的,你自己找
#include <stdio.h>
int main()
{
    float num1,num2,result;
    char operate;

    printf("Please enter operator:");
    scanf("%c",&operate);
    printf("Please enter two numbers:");
    scanf("%f,%f",&num1,&num2);

    switch (operate)
    {
      case'+':
      result=num1+num2;
      printf("%5.2f+%5.2f=%5.2f",num1,num2,result);
      break;

      case'-':
      result=num1-num2;
      printf("%5.2f-%5.2f=%5.2f",num1,num2,result);
      break;

      case'*':
      result=num1*num2;
      printf("%5.2f*5.2f=%5.2f",num1,num2,result);
      break;

      case'/':
      if (num2!=0)
      {
          result=num1/num2;
          printf("%5.2f/%5.2f=%5.2f",num1,num2,result);
      }
      else
          printf("In a division operation, the divisor can not be zero");
      break;

      default:
      printf("The operator is invalid");
    }

}





[此贴子已经被作者于2020-4-7 19:29编辑过]


把学习时间浪费在混坛上是傻瓜行为,更何况自己的水平连一两都没到。
2020-04-07 18:09
x1921171331
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2020-4-7
收藏
得分:0 
回复 2楼 叶纤
谢谢
2020-04-07 18:44
天下天下
Rank: 2
等 级:论坛游民
帖 子:62
专家分:15
注 册:2013-10-14
收藏
得分:7 
回复 楼主 x1921171331 自己对比吧
#include <stdio.h>
int main(void)
{
    float num1,num2,result;
    char operate;

    printf("Please enter operator:");
    scanf("%c",&operate);
    printf("Please enter two numbers:");
    scanf("%f,%f",&num1,&num2);

    switch (operate)
    {
      case'+':
      result=num1+num2;
      printf("%5.2f+%5.2f=%5.2f",num1,num2,result);
      break;

      case'-':
      result=num1-num2;
      printf("%5.2f-%5.2f=%5.2f",num1,num2,result);
      break;

      case'*':
      result=num1*num2;
      printf("%5.2f*5.2f=%5.2f",num1,num2,result);
      break;

      case'/':
      if (num1 == 0)
      {
          result=num1/num2;
          printf("%5.2f/%5.2f=%5.2f",num1,num2,result);
      }
          else
          printf("In a division operation, the divisor can not be zero");
      break;

      default:
      printf("The operator is invalid");
    }

}
2020-04-07 18:55
x1921171331
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2020-4-7
收藏
得分:0 
回复 4楼 天下天下
谢谢
2020-04-07 19:23
叶纤
Rank: 8Rank: 8
等 级:禁止访问
威 望:1
帖 子:658
专家分:848
注 册:2019-11-22
收藏
得分:0 
以下是引用天下天下在2020-4-7 18:55:00的发言:

#include <stdio.h>
int main(void)
{
    float num1,num2,result;
    char operate;

    printf("Please enter operator:");
    scanf("%c",&operate);
    printf("Please enter two numbers:");
    scanf("%f,%f",&num1,&num2);

    switch (operate)
    {
      case'+':
      result=num1+num2;
      printf("%5.2f+%5.2f=%5.2f",num1,num2,result);
      break;

      case'-':
      result=num1-num2;
      printf("%5.2f-%5.2f=%5.2f",num1,num2,result);
      break;

      case'*':
      result=num1*num2;
      printf("%5.2f*5.2f=%5.2f",num1,num2,result);
      break;

      case'/':
      if (num1 == 0)
      {
          result=num1/num2;
          printf("%5.2f/%5.2f=%5.2f",num1,num2,result);
      }
          else
          printf("In a division operation, the divisor can not be zero");
      break;

      default:
      printf("The operator is invalid");
    }

}

除法不可以除数为0的

把学习时间浪费在混坛上是傻瓜行为,更何况自己的水平连一两都没到。
2020-04-07 19:31
hbccc
Rank: 5Rank: 5
等 级:职业侠客
威 望:5
帖 子:108
专家分:315
注 册:2020-2-18
收藏
得分:7 
scanf后面不是c,应该是%c
2020-04-07 19:40
快速回复:我是名新手,下列程序哪里错误如何纠正,请大神赐教
数据加载中...
 
   



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

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