I am executing all my c/c++ programs in VC++ cmpiler.

#include <iostream>

using namespace std;

int main()
{
int age;
char sex;


cout<<"please input your age:";

cout<<"please input your sex (M/F):";
cin>> age;
cin>> sex;
if (age < 100) {
cout<<"you are pretty young!\n";
}
else if (age ==100 && sex == 'm')
{
cout<<"you are pretty old,and you are male!\n";
}
else if (age ==100 && sex == 'f')
{
cout<<"you are pretty old, and u r a female!\n";
}
else
{
cout<<"You are relly old!\n";
}
}

When I try to execute the above program,it gave the following error.
fatal error LNK1169: one or more multiply defined symbols found.
I tried google.com to correct this error by myself.But I counldn’t figure it out.Please help me.

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

Please use code tags instead, and watch spaces like in using namespace or else if .

#include<iostream>

using namespace std;

int main()
{
   int age;
   char sex;

   cout<<"please input your age:";

   cout<<"please input your sex (M/F):";
   cin>> age;
   cin>> sex;
   if ( age < 100 )
   {
      cout<<"you are pretty young!\n";
   }
   else if ( age ==100 && sex == 'm' )
   {
      cout<<"you are pretty old,and you are male!\n";
   }
   else if ( age ==100 && sex == 'f' )
   {
      cout<<"you are pretty old, and u r a female!\n";
   }
   else
   {
      cout<<"You are relly old!\n";
   }
}

Any problem with this?

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

Thanks for your reply.But still after took care of spaces,it displays that same error.Please help me.I am new to programming.

#include<iostream>
usingnamespace std;
 
int main() 
{
int age; 
char sex;
 
cout<<"please input your age:"; 
 
cout<<"please input your sex (M/F):";
cin>> age; 
cin>> sex;

if (age < 100){ 
cout<<"you are pretty young!\n";
}else if (age == 100 && sex == 'm'){
cout<<"you are pretty old,and you are male!\n";
}else if (age == 100 && sex == 'f'){
cout<<"you are pretty old, and u r a female!\n";
}else{
cout<<"You are relly old!\n";
}
}

Also,i don't know,how to give programs in code.I used

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

The same program works fine with me.
Which OS and compiler (version) are u using?

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

OS-windows.XP

Compiler-Microsoft VC++ 2005 enterprise edition

Please help me.I couldn't able to correct that problem.

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

There must be some information that you can see that you're not telling us. How did you set up the project? Are there other files in it? Etc.?

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

Yes,the project has 2 more files with it.I thought in one project we can place more files.

Thanks for the reply and help me.How can i run this file when more that one file is stored in same project.

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

You can have more files, but as the linker seems to be telling you, you can't have the same thing defined in more than one place. I don't suppose you'd care to post all the relevant code?

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

This is the full error message

Ex2agesex.obj : error LNK2005: _main already defined in Ex1Sum.obj
Ex3currencydollar.obj : error LNK2005: _main already defined in Ex1Sum.obj
C:\Documents and Settings\Mohan.RBCHRIT7\My Documents\Visual Studio 2005\Projects\OwnPrograms\Debug\OwnPrograms.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://c:\Documents and Settings\Mohan.RBCHRIT7\My Documents\Visual Studio 2005\Projects\OwnPrograms\Debug\BuildLog.htm"
OwnPrograms - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How would i set some file as main to run in VC++

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

Well there you go. You've got main defined in more than one file. You can only have one main . Just like the messages are saying. You need a single entry point to your program -- decide where it should be.

And again, if you want help with code, it is highly advisable that you post the code you want help with.

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

Dave thanks for your help and apologize for not asking my question properly.I thought that fatal error would be the problem for my program.

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

My first program in a project is

#define _CRT_SECURE_NO_DEPRECATE//to take of scanf deprecated warning
#include<stdio.h>
#include<math.h>
//int main()
{
int a,b;
double aSquare,bSquare,sumOfSquare;
printf("input first number\n");
scanf("%d",&a);
printf("input second number\n");
scanf("%d",&b);
printf("sum %d\n",a+b);
printf("average %d\n",(a+b)/2);
aSquare=sqrt(a);
bSquare=sqrt(b);
sumOfSquare=aSquare+bSquare;
printf("sumOfSquare %f\n",sumOfSquare);
}

As you told i have taken off main from it.and my second file is

#include <iostream>
using namespace std;
int main() 
{
int age; 
char sex;
 
cout<<"please input your age:"; 

cout<<"please input your sex (M/F):";
cin>> age; 
cin>> sex;
//cin.ignore(); 
if (age < 100){ 
cout<<"you are pretty young!\n";
}else if (age == 100 && sex == 'm'){
cout<<"you are pretty old,and you are male!\n";
}else if (age == 100 && sex == 'f'){
cout<<"you are pretty old, and u r a female!\n";
}else{
cout<<"You are relly old!\n";
}
// cin.get();
}

how can i call the first program in the second one.Displaying two programs output in second file.Please help me.

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

Make it a function called something other than main , then call it from the other code.

Re: fatal error LNK1169: one or more multiply defined symbols found. 80 80

Thanks Dave. Your answer solved my problem as well.

Be a part of the DaniWeb community

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