I am trying to write a program that computes the area of a right triangle. It has to use a function to compute the area. This is actually a part of a bigger program, but when I couldn't get it to work I isolated this section. I tried looking on google for help, but nothing I found seemed to help. I get no errors when I compile, but when I try to execute I get the following error:
Linking...
area.obj : error LNK2001: unresolved external symbol "double __cdecl findarea(double,double)" (?findarea@@YANNN@Z)
Debug/area.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.area.exe - 2 error(s), 0 warning(s)
Below is my code:
//Program to compute the area of a right triangle
#include <iostream>
#include <iomanip>
#include <fstream>
//Declare std
using std::cout;
using std::cin;
using std::endl;
using std::ios;
using std::cerr;
using std::ofstream;
//Function Prototype
double findarea (double,double);
//Start the program
int main ()
{
//Declare the variables
double a; //side a
double b; //side b
double d; //area
//Open the file for output
ofstream datafile ("program.txt", ios::out);
//Error routine if file can not be created
if (!datafile) {
cerr << "File could not be opened" << endl;
exit (1);
}
//Initialize a
a=1;
//Describe program to user
cout << "This program will compute the area of a right triangle.\n\nSet side a or b to 0 or less to end the program.";
datafile << "This program will compute the area of a right triangle.\n\nSet side a or b to 0 or less to end the program.";
//Begin the WHILE loop to set sentinal value to loop the program
while (a>0){
//Get a
cout << "\n\nEnter the length of side a: " << endl;
cin >> a;
datafile << "\n\nSide a is: " << a << endl;
//Use an IF to dictate the behavior of the program if a>0 and get b
if (a>0){
cout << "\nEnter the length of side b: " << endl;
cin >> b;
datafile <<"Side b is: " << b << endl;
//Allow for b<=0
if (b<=0){
cout << "\n\nYou have ended the program." << endl;
datafile << "You have ended the program." << endl;
break;
}
d=findarea(a,b);
cout << "\nThe area is: " << d << endl;
datafile << "The area is: " << d << endl;
//End IF
}
//Start ELSE to allow output that tells the user they have ended the program
else {
cout << "\n\nYou have ended the program." << endl;
datafile << "You have ended the program." << endl;
//End ELSE
}
//End WHILE
}
//End program
return 0;
}
double findarea (double q,double r,double s) {
s=(q*r)/2;
return s;
}
Any pointers/help would be appreciated.
TIA
Heather