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;
}
// 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.
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;
}