Answered by:
LINK2019 error in my functions
Question

Hello!
I am trying to compile a program to calculate the cos, sin, and tan of angles and I got this far and the LINK2019 came up on my functions. Wh
# include<string> # include <iostream> # include <iomanip> # include <cmath> using namespace std; struct Angle { double sin, cos, tan,beta; int degrees[3]; double radians[3]; }; int getChoice(int); Angle calcRad(int[],const double); Angle getCos(double[]); Angle getSin(double[]); Angle getTan(double[]); int main() { const int SIZE = 3; const double PI = 3.1415; const int GET_RAD = 1, GET_SIN = 2, GET_COS = 3, GET_TAN = 4, EXIT = 5; string name; cout << "Enter sides for triangle"; int choice = 0; while (choice != 5) { choice = getChoice(choice); Angle cvt; switch (choice) { case GET_RAD: calcRad(cvt.degrees,PI); break; case GET_COS: getCos(cvt.radians); break; case GET_SIN: getSin(cvt.radians); break; case GET_TAN: getTan(cvt.radians); break; } } cout << "Enter you name for this project ;"; getline(cin, name); } int getChoice(int choice) { cout << "Calculate Trigometric Functions from an Angle" << endl; cout << "Choose from the following :" << endl; cout << "1. Convert degrees to radians : " << endl; cout << "2.Get the Cosine of the angle : " << endl; cout << "3.Get the Sine of the Angle : " << endl; cout << "4. Get the Tangent of the Angle : " << endl; cout << "5. Exit :" << endl; cout << "What is you choice? : " << endl; cin >> choice; while(choice>0choice<6) { return choice; } return 0; } Angle calcRad(int degrees, double const PI) { Angle side; for (int count = 0; count < 3; count++) { cout << "Enter the degrees of the angle:"; cin >> side.degrees[count]; } double radians = side.degrees[3] * (PI / 180); for (int start = 0; start < 3; start++) { cout << "The degrees in radians would be:"; cout << setprecision(4) << fixed << endl; side.radians[start]; } return side; } Angle getCos(double radians) { Angle theta; for (int index = 0; index < 3; index++) theta.radians[index]; for (int i = 0; i < 3; i++) { theta.radians[i] = cos(radians); cout << "The cosine would be :" << theta.radians[i] << endl; } return theta; } Angle getSin(double radians) { Angle theta; for (int index = 0; index < 3; index++) theta.radians[index]; for (int i = 0; i < 3; i++) { theta.radians[i] = sin(radians); cout << "The cosine would be :" << theta.radians[i] << endl; } return theta; } Angle getTan(double radians) { Angle theta; for (int index = 0; index < 3; index++) theta.radians[index]; for (int i = 0; i < 3; i++) { theta.radians[i] = tan(radians); cout << "The tangent would be :" << theta.radians[i] << endl; } return theta; }
at does it mean and how do I fix it?
Thanks,
Answers

Hello!
I am trying to compile a program to calculate the cos, sin, and tan of angles and I got this far and the LINK2019 came up on my functions. Wh
# include<string> # include <iostream> # include <iomanip> # include <cmath> using namespace std; struct Angle { double sin, cos, tan,beta; int degrees[3]; double radians[3]; }; int getChoice(int); Angle calcRad(int[],const double); Angle getCos(double[]); Angle getSin(double[]); Angle getTan(double[]); int main() { const int SIZE = 3; const double PI = 3.1415; const int GET_RAD = 1, GET_SIN = 2, GET_COS = 3, GET_TAN = 4, EXIT = 5; string name; cout << "Enter sides for triangle"; int choice = 0; while (choice != 5) { choice = getChoice(choice); Angle cvt;
What values do you think the members of cvt contain?
switch (choice) {
What happens if a user enters an invalid value for choice?
What happens if a user chooses a value other than 1 in the first iteration?
case GET_RAD: calcRad(cvt.degrees,PI); break; case GET_COS: getCos(cvt.radians);
Your function declarations and definitions both say the functions return a value yet you never use that value.
break; case GET_SIN: getSin(cvt.radians); break; case GET_TAN: getTan(cvt.radians); break; } } cout << "Enter you name for this project ;"; getline(cin, name); } int getChoice(int choice) { cout << "Calculate Trigometric Functions from an Angle" << endl; cout << "Choose from the following :" << endl; cout << "1. Convert degrees to radians : " << endl; cout << "2.Get the Cosine of the angle : " << endl; cout << "3.Get the Sine of the Angle : " << endl; cout << "4. Get the Tangent of the Angle : " << endl; cout << "5. Exit :" << endl; cout << "What is you choice? : " << endl; cin >> choice; while(choice>0choice<6)
Is there any value for which this expression is false?
{ return choice; } return 0; } Angle calcRad(int degrees, double const PI) { Angle side; for (int count = 0; count < 3; count++) { cout << "Enter the degrees of the angle:"; cin >> side.degrees[count]; } double radians = side.degrees[3] * (PI / 180);
There is no object named side.degrees[3].
for (int start = 0; start < 3; start++) { cout << "The degrees in radians would be:"; cout << setprecision(4) << fixed << endl; side.radians[start];
What do you think this statement does?
} return side; }
Angle getCos(double radians) { Angle theta; for (int index = 0; index < 3; index++) theta.radians[index];What do you think this statement does?
for (int i = 0; i < 3; i++) { theta.radians[i] = cos(radians); cout << "The cosine would be :" << theta.radians[i] << endl; } return theta; } Angle getSin(double radians) { //snip
} Angle getTan(double radians) { //snip }
at does it mean and how do I fix it?
Thanks,
 Marked as answer by Brian Holcer Friday, October 18, 2019 11:03 PM
All replies

The code declares functions but the function definitions by the same name do not match the declarations. So the code that uses the functions as they are declared is referencing functions that, as far as the linker is concerned, do not exist.
For example 
Declaration 
Angle calcRad(int[],const double);
Definition
Angle calcRad(int degrees, double const PI)
Fix the function definitions to conform to the declarations.
The same type of error was made in code you wrote in this thread https://social.msdn.microsoft.com/Forums/vstudio/enUS/7ea90a27cb744378a96154ebe63c6054/c0142andc2109errorsonc?forum=vcgeneral
 Edited by RLWA32 Thursday, October 17, 2019 11:21 PM
 Proposed as answer by SuarezZhouMicrosoft contingent staff Friday, October 18, 2019 1:25 AM

Hello,
Thank you for posting here.
As RLWA32 said, The mismatch between function declaration and function definition leads to your error. Besides, your function has many logical errors and meaningless statements. You can try the following code. I have corrected it for you. You can compare it with your own code, I hope it will help you.
# include<string> # include <iostream> # include <iomanip> # include <cmath> using namespace std; struct Angle { double sin, cos, tan, beta; int degrees[3]; double radians[3]; }; int getChoice(int); Angle calcRad(/*int[],*/ const double); Angle getCos(double[]); Angle getSin(double[]); Angle getTan(double[]); int getChoice(int choice) { cout << "Calculate Trigometric Functions from an Angle" << endl; cout << "Choose from the following :" << endl; cout << "1. Convert degrees to radians : " << endl; cout << "2.Get the Sine of the Angle : " << endl; cout << "3.Get the Cosine of the angle : " << endl; cout << "4. Get the Tangent of the Angle : " << endl; cout << "5. Exit :" << endl; cout << "What is you choice? : " << endl; cin >> choice; while (choice > 0  choice < 6) { return choice; } return 0; } Angle calcRad(/*int degrees[],*/ const double PI)//degrees(array) has no meaning. You can define PI globally, so PI will make no sense too. { Angle side; for (int count = 0; count < 3; count++) { cout << "Enter the degrees of the angle:"; cin >> side.degrees[count]; } //double radians = side.degrees[start] * (PI / 180); it has no meaning here for (int start = 0; start < 3; start++) { side.radians[start] = side.degrees[start] * (PI / 180);//Convert degrees to radians, and save it in a Angle object cout << "The degrees in radians would be:"; cout << fixed << setprecision(4) << side.radians[start] <<endl; //side.radians[start]; } return side;//return the Angle object which has data } Angle getCos(double radians[]) { Angle theta; /*for (int index = 0; index < 3; index++) it has no meaning here theta.radians[index];*/ for (int i = 0; i < 3; i++) { theta.radians[i] = cos(radians[i]); cout << "The cosine would be :" << theta.radians[i] << endl; } return theta; } Angle getSin(double radians[]) { Angle theta; /*for (int index = 0; index < 3; index++) it has no meaning here theta.radians[index];*/ for (int i = 0; i < 3; i++) { theta.radians[i] = sin(radians[i]); cout << "The sine would be :" << theta.radians[i] << endl; } return theta; } Angle getTan(double radians[]) { Angle theta; /*for (int index = 0; index < 3; index++) it has no meaning here theta.radians[index];*/ for (int i = 0; i < 3; i++) { theta.radians[i] = tan(radians[i]); cout << "The tangent would be :" << theta.radians[i] << endl; } return theta; } int main() { const int SIZE = 3; const double PI = 3.1415; const int GET_RAD = 1, GET_SIN = 2, GET_COS = 3, GET_TAN = 4, EXIT = 5; string name; cout << "Enter sides for triangle"<<endl; int choice = 0; while (choice != 5) { choice = getChoice(choice); Angle cvt; switch (choice) { case GET_RAD: cvt=calcRad(/*cvt.degrees,*/ PI);//calcRad return the Angle object which has data, So cvt you define can be used to receive data break; case GET_SIN: getSin(cvt.radians); break; case GET_COS: getCos(cvt.radians); break; case GET_TAN: getTan(cvt.radians); break; } } cout << "Enter you name for this project ;"; getline(cin, name); }
Best Regards,
Suarez Zhou
 Edited by SuarezZhouMicrosoft contingent staff Friday, October 18, 2019 1:59 AM

Hello!
I am trying to compile a program to calculate the cos, sin, and tan of angles and I got this far and the LINK2019 came up on my functions. Wh
# include<string> # include <iostream> # include <iomanip> # include <cmath> using namespace std; struct Angle { double sin, cos, tan,beta; int degrees[3]; double radians[3]; }; int getChoice(int); Angle calcRad(int[],const double); Angle getCos(double[]); Angle getSin(double[]); Angle getTan(double[]); int main() { const int SIZE = 3; const double PI = 3.1415; const int GET_RAD = 1, GET_SIN = 2, GET_COS = 3, GET_TAN = 4, EXIT = 5; string name; cout << "Enter sides for triangle"; int choice = 0; while (choice != 5) { choice = getChoice(choice); Angle cvt;
What values do you think the members of cvt contain?
switch (choice) {
What happens if a user enters an invalid value for choice?
What happens if a user chooses a value other than 1 in the first iteration?
case GET_RAD: calcRad(cvt.degrees,PI); break; case GET_COS: getCos(cvt.radians);
Your function declarations and definitions both say the functions return a value yet you never use that value.
break; case GET_SIN: getSin(cvt.radians); break; case GET_TAN: getTan(cvt.radians); break; } } cout << "Enter you name for this project ;"; getline(cin, name); } int getChoice(int choice) { cout << "Calculate Trigometric Functions from an Angle" << endl; cout << "Choose from the following :" << endl; cout << "1. Convert degrees to radians : " << endl; cout << "2.Get the Cosine of the angle : " << endl; cout << "3.Get the Sine of the Angle : " << endl; cout << "4. Get the Tangent of the Angle : " << endl; cout << "5. Exit :" << endl; cout << "What is you choice? : " << endl; cin >> choice; while(choice>0choice<6)
Is there any value for which this expression is false?
{ return choice; } return 0; } Angle calcRad(int degrees, double const PI) { Angle side; for (int count = 0; count < 3; count++) { cout << "Enter the degrees of the angle:"; cin >> side.degrees[count]; } double radians = side.degrees[3] * (PI / 180);
There is no object named side.degrees[3].
for (int start = 0; start < 3; start++) { cout << "The degrees in radians would be:"; cout << setprecision(4) << fixed << endl; side.radians[start];
What do you think this statement does?
} return side; }
Angle getCos(double radians) { Angle theta; for (int index = 0; index < 3; index++) theta.radians[index];What do you think this statement does?
for (int i = 0; i < 3; i++) { theta.radians[i] = cos(radians); cout << "The cosine would be :" << theta.radians[i] << endl; } return theta; } Angle getSin(double radians) { //snip
} Angle getTan(double radians) { //snip }
at does it mean and how do I fix it?
Thanks,
 Marked as answer by Brian Holcer Friday, October 18, 2019 11:03 PM