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.

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?

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

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

OS-windows.XP

Compiler-Microsoft VC++ 2005 enterprise edition

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

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.?

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.

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?

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++

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.

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.

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.

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

Thanks Dave. Your answer solved my problem as well.

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.