如何获得输出(逐步) [英] how to get output(step wise)

查看:97
本文介绍了如何获得输出(逐步)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream.h>
void main()
{
  long umber=7583241;
  int first=0,secind=0;
  do
  {
    int r= number%10;
    if(r%2==0)
      first+=r;
    else
      second+=r;
    number/=10;
  } while (number>0)
  cout<<first-second;
}

推荐答案

您应该首先修复代码,因为它无法编译。



要获得逐步输出,你必须在每一步写出输出,例如



You should first fix the code, as it stands it wouldn't compile.

To get stepwise output, you have to, well, write the output at each step, e.g.

do
  {
    int r= number % 10;
    if(r%2==0)
      first+=r;
    else
      second+=r;

   cout << "number: " << number << ", r: " << r << ", first: " << first << ", second: " << second << endl;
    number/=10;
  } while (number>0);


首先纠正语法错误:

1)您将其声明为umber并将其用作数字

2)您将其声明为secind并将其用作second

3)你需要在之后使用分号,而条件。



修复这些,它可能会编译。它可能不会 工作 - 但我不知道它应该做什么,所以我不能在现阶段说。但是直到它编译没有错误,它根本不会运行...
Start by correcting the syntax errors:
1) You declare it as "umber" and use it as "number"
2) you declare it as "secind" and use it as "second"
3) You need a semicolon after the while condition.

Fix those, and it might compile. It might not work - but I have no idea what it is supposed to do, so I can't say at this stage. But until it compiles without errors, it won't run at all...


这篇关于如何获得输出(逐步)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆