• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

C++ help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

metallica0421

Member
Joined
Jul 26, 2002
ok im writing this program for my c++ class, were supposed to aks the user how many times he wants the fibonacci sequence done. BUT i keep getting this error-
fib prog.obj : error LNK2005: _main already defined in 12.obj
Debug/p363.exe : fatal error LNK1169: one or more multiply defined symbols found

heres my code-
Code:
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <math.h>

//function declarations

int GetData();
void CalcFib(int seq);

int main()
{
	int seq;
	seq=GetData();
	system ("CLS");
	CalcFib(seq);
	return 0;
}
int GetData()
{
	/*
	task:obtain 3 of times sequence must be done
	Data in: nada
	Data out: uno interger
	*/
	int seq;
	do
	{
		cout<<"Enter ho wmany times you want the sequence done. "<<endl;
		cin>>seq;
		if(seq<0)
		{
			system("cls");
			cout<<"YOU ENTERED A NEGATIVE NUMBER"<<endl;
		}
	}
	while(seq<0);
	return seq;
}
void CalcFib(int seq)
{
	/*
	task: display the sequence
	Data in:# of desired sequences
	Data out:nada
	*/
	int x, num1, num2, num3, nada;
	num1=0;
	num2=1;
	cout<<"the number of times the sequence was done" << seq<<endl;
	if(seq==1)
		cout<<"0"<<endl;
	else if(seq==2)
		cout<< " " <<num1 << " " << num2;
	else
	{
		cout<<" "<< num1 << " " << num2 << " ";
	for(x=1; x<=(seq-2); x++)
		{
			num3=num1+num2;
			cout<<num3<<endl;
			nada=num2;
			num2=nada;
		}
	}
	cout<<endl<<endl;
	
}
 
Last edited by a moderator:
man your code needs spaces and tabs to make it readable. I will see what I can find for ya
 
it does have spaces and tabs but when i posted it it screwed it up, if i click edit it shows up with spaces and tabs
 
Sure you don't have other things that you're trying to link that with? Other files in the workspace if you're using Visual C++, or not being selective enough with your link statement if you're using something like gcc
 
oops hehe, i had another file on the same project, i got rid of it and now it runs BUT........the fibonacci sequence doestn turn our right, i type in 10, and i get 0 1111111111, when what i shuld get is 0 1 1 2 3 5 8 13 21 34
 
it is your nada here is how it should look.....

#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <math.h>

//function declarations

int GetData();
void CalcFib(int seq);

int main()
{
int seq;
seq=GetData();
system ("CLS");
CalcFib(seq);
return 0;
}

int GetData()
{
/*
taskbtain 3 of times sequence must be done
Data in: nada
Data out: uno interger
*/
int seq;
do
{
cout<<"Enter ho wmany times you want the sequence done. "<<endl;
cin>>seq;
if(seq<0)
{
system("cls");
cout<<"YOU ENTERED A NEGATIVE NUMBER"<<endl;
}
}
while(seq<0);
return seq;
}

void CalcFib(int seq)
{
/*
task: display the sequence
Data in:# of desired sequences
Data out:nada
*/
int x, num1, num2, num3, nada;
num1=0;
num2=1;
cout<<"the number of times the sequence was done" << seq<<endl;
if(seq==1)
cout<<num1<<endl;
else if(seq==2)
cout<< " " <<num1 << " " << num2;
else
{
cout<<" "<< num1 << " " << num2;
for(x=1; x<=(seq-2); x++)
{
num3=num1+num2;
cout<<" " << num3;
num1=num2;
num2=num3;
}
}
cout<<endl<<endl;

}
 
darn they did take the tabs out!!! you need to take num2 and assign it to num1 then assign num3 to num2 instead of using the variable nada
 
Back