Blockland Forums > General Discussion
Torque Script
<< < (2/11) > >>
Jakobblockhead:
Torquescript is almost identical to C++. I almost barfed because you were asking help from people while lying to their faces.
Madara:
#include<stdio.h>
 
int Fibonacci(int);
 
int main()
{
   int n, i = 0, c;
 
   scanf("%d",&n);
 
   printf("Fibonacci series\n");
 
   for ( c = 1 ; c <= n ; c++ )
   {
      printf("%d\n", Fibonacci(i));
      i++;
   }
 
   return 0;
}
 
int Fibonacci(int n)
{
   if ( n == 0 )
      return 0;
   else if ( n == 1 )
      return 1;
   else
      return ( Fibonacci(n-1) + Fibonacci(n-2) );
Xalos:

* Missing a closing bracket for int Fibonacci
* No catch case for negative numbers, meaning that calling Fibonacci for all n < 0 causes an infinite loop
* Defines a function signature when defining the same function later on in the same script file
Madara:
This has been my first time posting a thread.
I apologize for my lack of consideration.
Ipquarx:

--- Quote from: Xalos on April 04, 2014, 06:25:37 PM ---
* Defines a function signature when defining the same function later on in the same script file
--- End quote ---
You need to do that in C++, as the compiler doesn't look ahead for references.

However...

* Used an extra loop variable i when you could've just used c - 1 for input to the fibonacci method
* Didn't put the increment statement for i after the increment statement for c
* Coded the Fibonacci method in such a way that it will recurse 2n+1 times
People can be nitpicky on the forums. Just look at some of the tutorials and resources in the coding help subforum and learn from that, you shouldn't have too much trouble. Make a new topic there if you want more help.
Navigation
Message Index
Next page
Previous page

Go to full version