【发布时间】:2015-05-28 01:18:32
【问题描述】:
我正在尝试用 C++ 制作斐波那契数列生成器,但遇到了一些麻烦。我是 C++ 的新手,我正在尝试用我知道的其他语言完成这项工作。于是我写了一个程序:
#include <iostream>
using namespace std;
int NextNumber(int x, int y, int z)
{
z=x+y;
return z;
}
int main()
{
int q;
int w;
int x=0;
int y=1;
int z=1;
int t=1;
cout << x;
cout << ", "<< y ;
cout << ", "<< z ;
while (t<10)
x=NextNumber(y,z,x);
cout << ", "<< x ;
q=y; //Q is farthest back
w=z; //W is in the middle
z=x; //Z moves from middle to front
y=w; //Y moves from back to middle
x=q; //X moves from front to back
t=t+1; //Add a rotation to the while loop
}
我正在使用 Xcode 进行编译,运行程序时似乎没有显示任何输出。如果有人对为什么会发生这种情况有任何想法,或者我的程序有任何逻辑缺陷,请提供帮助。谢谢。
【问题讨论】:
-
将
<<std::endl' after you didsplayx` 放置会有所帮助,这样您实际上可以在新行上显示内容。检查您的项目参数以确保您正在制作控制台程序