i dont know if this code is right because i'm trying to create a program that display the fibonacci value of a number with FUNCTIONS combining pass by the VALUE and pass by REFERENCE

please i needyour helpfor my preparation for my exam

#include <iostream.h> 
 
void fibonacci(int, int&. int&); 
 
int main(){ int num1=0, num2=1, num, fibo;
cout<<"Enter number of fibonacci value: ";
cin>>num;
 
if(num<=0)cout<<"invalid";
   if(num==1)
     cout<<"fibonacci value is"<<num1;
   else if(num==2)
     cout<<"fibonacci value is"<<num2; 
   else
      cout<<"fibonacci value of<<num<<"is" <<fibo;
 
fibonacci(num,num1,num2);
} 
 
void fibonacci(int num, int&num1, int&num2)
{ int ctr=2,fibo;
  while(ctr<num)
  {fibo=num1+num2;
    num1=num2;
    num2=fibo;ctr++;
   }
return;
}

please help me with function,I;m really having a hard time to understand FUNCTIONS

#include<iostream.h>
#include<conio.h>
void fibonacci (int&,int);
int main( )
{ clrscr();
  int num;
  cout<<"Enter a number: ";
  cin>>num;
  cout<<"The fibonacci of "<<num<<"is: ";
  getch();
  return 0;
}
void fibonacci ( int& fibo, int num);
{int a=0, b=1, ctr;
 if (num==1)
  return;
 else if (num==2)
    f=1;
    return;
 else if (num>2)
     {
      for (ctr=3;ctr<=num;ctr++)
             {
              f=a+b;
              a=b;
              b=f; 
             }
     }
return;
}

this is the other codebut it has a error said
"declaration terminated incorrectly"

in my first code,the coderun but not display the proper fibonacci value
e.g i input number 5,the fibonacci value of 5 is 3(right)but it dispaly 1258????


please help me i need the code correctly

thanks

remove the semicolon at line 13

>>e.g i input number 5,the fibonacci value of 5 is 3(right)

Not unless you made a typo. The Fibonacci number is the sum of the two previous numbers in the sequence. such as 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.

>>but it dispaly 1258????
The code you posted doesn't display anything. In fact, it doesn't even call the fibonacci function.

oops theres an error again

1. misplaced else
2.unreachable code
3. parameter fibo is never beeb use?

please help....i'm really stuck

i reallly dont know what to do


please help

thanks

lines 17, 18 and 19. you need to add '{' after line 17 and '}' before line 20. That will fix the first two error messages you got.

>>3. parameter fibo is never beeb use?
That is telling you that the function has a parameter that is not used inside the function. Many compilers complain about such things. The way to remove the error is to either add something inside the function that references the parameter or remove the parameter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.