unresolved external symbol

Hello - would really appreciate some help with this.... compiler returns this error: 1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>c:\visual studio 2010projects\learn2\Debug\learn2.exe : fatal error LNK1120: 1 unresolved externals

Code below many thanks in advance.

// learning.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

/*Write a struct to hold a fraction. The struct should have a integer numerator and a integer denominator member.
Declare 2 fraction variables and read them in from the user. Write a function called multiply that takes both fractions,
multiplies them together, and prints the result out as a decimal number.*/

// Fraction structure to hold int numerator and int denominator
struct Fraction
{
int iNum;
int iDen;
};

int readInNumerator()
{
cout<< "Enter the numerator : ";
int n;
cin >> n;
return n;
}

int readInDenominator()
{
cout<< "Enter the denominator : ";
int d;
cin >> d;
return d;
}


float convertToFloat(int nValue1, int nValue2)
{
float fValue = static_cast<float>(nValue1) / nValue2;

return fValue;
}


int tmain()
{

// Read in 2 variables from user
Fraction sFractionOne;
sFractionOne.iNum = readInNumerator(); //Initialise iNum in structure FractionOne
sFractionOne.iDen = readInDenominator(); //Initialise iNum in structure FractionOne

Fraction sFractionTwo;
sFractionTwo.iNum = readInNumerator(); //Initialise iNum in structure FractionTwo
sFractionTwo.iDen = readInDenominator(); //Initialise iNum in structure FractionTwo


// Multipy both fractions together and print out as a decimal number.

// Convert fracton to double

float decimalFractionOne = convertToFloat(sFractionOne.iNum,sFractionOne.iDen );
float decimalFractionTwo = convertToFloat(sFractionTwo.iNum,sFractionTwo.iDen);

// Multiply fractions together

float fResult = decimalFractionOne * decimalFractionTwo;

// Print out result

cout <<" The result is : " << fResult;


return 0;
}

The entry point of a program is main, not tmain. Rename that function.
Be careful with this function:

1
2
3
4
5
6
float convertToFloat(int nValue1, int nValue2)
{
float fValue = static_cast<float>(nValue1) / nValue2;

return fValue;
}


if nValue2 ever equals zero, then you have a division by zero which is undefined.

Try this:
1
2
3
4
5
6
7
8
9
10

float convertToFloat(int nValue1, int nValue2)
{

if(nValue2 == 0)//avoid division by zero
return nValue1;//return an assumption of division by 1
float fValue = static_cast<float>(nValue1) / nValue2;

return fValue;
}
Many Thanks ..... for the help very much appreciated !!! -
Topic archived. No new replies allowed.