Hey ppl,
Im trying to solve some problems for topcoder website for practice purposes. But the compiler shows the following error for the codes i've been compiling. I have no problems compiling these codes with Borland C++. I've posted the errors and code below.

Errors:

Your code did not compile:

errors linking:

SquareDigits-stub.o(.text+0x240): In function `main':
: multiple definition of `main'
SquareDigits.o(.text+0x174): first defined here
/usr/bin/ld: Warning: size of symbol `main' changed from 69 in SquareDigits.o to 532 in SquareDigits-stub.o
collect2: ld returned 1 exit status

#include<iostream>

using namespace std;

class SquareDigits
{
	public:
		int smallestResult (int);
};

int SquareDigits :: smallestResult (int n)
{
	int digitCount,quotient,digits[5];
	cout << "Please enter the no of digits in the no entered :" << endl;
	cin >> digitCount;
	quotient = n;
	cout << "The digits of the number entered are listed below :" <<endl;
	for (int i=0; i<digitCount; i++)
	{
		
		digits[i] = quotient%10;
		quotient = n/10;
		cout << digits[i] << endl;
	}
	return 0;
}

int main()
{
	SquareDigits s;
	int sample;
	cout << "Enter a no :" << endl;
	cin >> sample;
	s.smallestResult(sample);
	return 0;
}

PS: This code is not complete. This code just extracts digits from a given no and saves it in an array for now.

> SquareDigits-stub.o ...
> SquareDigits.o
Both SquareDigits-stub.cpp AND SquareDigits.cpp contain a main()

Only one of them should be there.

What you do depends on what the situation is, but could include
- removing one of the files from the project
- renaming one of the main()'s
- commenting out one of the main()'s

In this case, if i comment out the main() which i created, the method will be executed automatically by the other main()?

Hey salem, checked by removing the main() which i coded. The code is working fine after that. Thanks for the suggestion.

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.