后续代码有什么问题? [英] What is the problem in the foloowing code?

查看:154
本文介绍了后续代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
using namespace std;
class fibonnaci{
	private:
		int n;
		public:	
	int fab(int k)
	{
		if ((k==1)||(k==0))
		{
			return (k);
		}
		else
		{
			return (fab(n-1)+fab(n-2));
		}
	}
};

int main()
{    int n,i=1;
    
	cout<<"Please input the number of terms for fibonnaci seroies:";
	cin:
	cin>>n;
	if(n<0)
	{
		cout<<"Cannot print Fibonnaci series for "<<n<<" \n";
		cout<<"Please enter correct number:";
		goto cin;
	}
	while(i<=n)
	{
		fibonnaci f;
		cout<<f.fab(i)<<" ";
		i++;
	}
	return 0;
}



我尝试过的事情:

尝试了所有事情,但我无法使代码正常工作?



What I have tried:

tried every thing but i cannot get the code to work?

推荐答案

忘记了,我犯了一个非常愚蠢的错误,现在无论如何我都感谢了它
got it i did a very stupid mistake and now i have got it thanks anyways
int fab(int k)
{
    if ((k==1)||(k==0))
    {
        return (k);
    }
    else
    {
        return (fab(k-1)+fab(k-2));
    }
}


有一个工具可以让您看到代码在做什么,它的名字叫debugger.精通调试器不是可选的,任何程序员都必须掌握,没有例外.
这也是一个很好的学习工具,因为它可以向您展示现实,并且您可以看到哪个期望与现实相匹配.当您不了解代码在做什么或为什么要做什么时,答案是调试器.
使用调试器查看您的代码在做什么.只需设置一个断点并查看您的代码执行情况,调试器就可以让您逐行执行第1行并在执行时检查变量,这是一个了不起的学习工具.

调试器-维基百科,免费百科全书 [ Visual Studio 2010中的精通调试-入门指南 [ ^ ]
使用Visual Studio 2010进行基本调试-YouTube [
There is a tool that allow you to see what your code is doing, its name is debugger. Mastering the debugger is not optional, it is mandatory for any programmer, no exception.
It is also a great learning tool because it show you reality and you can see which expectation match reality. When you don''t understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner''s Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
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天全站免登陆