请为此代码说明提供帮助 [英] Kindly need help for this code explaination

查看:66
本文介绍了请为此代码说明提供帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void main ()
{
int digit;
for (digit=0;digit<=9;digit++)
cout<<digit<<"\n";
digit=5*digit;
--digit;
cout<<digit;
}





我的尝试:





What I have tried:

void main ()
{
int digit;
for (digit=0;digit<=9;digit++)
cout<<digit<<"\n";
digit=5*digit;
--digit;
cout<<digit;
}

/ *我不知道49它是怎么来的* /

/* i dont know the 49 how its comes */

推荐答案

如果你知道C程序的基础知识工作,然后你可以轻松地将值映射到程序的输出,

If you know the basics of how C programs work, then you can easily map the value to the output of the program,
// Write clean code, it makes more sense.
void main ()
{
    int digit;                                    // create a new variables
    for (digit = 0; digit <= 9 ; digit++) {       // run the loop using "digit" variable
                                                  // until digit becomes 10
        cout << digit << "\n";                    // print current digit, each time
    }

    digit= 5 * digit;                             // Multiply last value of digit (10)
                                                  // with 5
    --digit;                                      // Decrease its value by 1 (--)
    cout << digit;                                  // Print it.
}



我们都知道5x10 = 50和50-1 = 49。如果这个程序没有意义,请让你的导师重新开始并再次教你这些,因为你根本不知道它们。这是初学者的常见问题,他们不了解基础知识,他们试图构建一些大的东西 - 这不起作用。


And we all know that 5x10=50 and 50-1=49. If this program doesn't make sense, please ask your instructor to start again and teach these to you again as you have no idea about them at all. This is a common problem among beginners, they don't understand the basics and they try to build something big — which does not work.


如何自己发现代码在做什么调试器的帮助?



你应该学会尽快使用调试器,这是一个不可思议的学习工具。而不是猜测你的代码在做什么,现在是时候看到你的代码正在执行并确保它能达到预期的效果。



Debugger - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么以及您的任务是与它应该做的比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
What about discovering by yourself what the code is doing with the help of debugger ?

You should learn to use the debugger as soon as possible, it is an incredible learning tool. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于请为此代码说明提供帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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