### can someone identify the error in my funtion?

I continue to get error:

 ``1234`` `````` try.cpp: In function `double trigSum(double, double)': try.cpp:30: parse error before `)' token try.cpp: In function `int main()': try.cpp:62: parse error before `return'``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263`` ``````// -------------------------------------------------------------------- // File name: simpleMath.cpp // Assign ID: LAB10 // Due Date: 11/07/12 at 7:30 pm // // Purpose: Performs a simple addiion between 2 items. // // Author: bfields Byron Fields // -------------------------------------------------------------------- #include #include #include using namespace std; // ----------------------------------------------------------------- // Function Name: trigSum // Purpose: Returns a value for calculations // // Invocation: sum = trigSum(double,double); // // ----------------------------------------------------------------- double trigSum(double num1,double num2) { double sum; sum = cos(num1) + sin(num2); return sum; } int main() { double num1; double num2; cout << "(c) 2012, bfields Byron Fields" << endl; cout << endl; cout << "===========================================" << endl; cout << endl; cout << "This function calculates the sum of cosine" << endl; cout << "of 1 Number and sine of another number." << endl; cout << "The given calculation is:" << endl; cout << endl; cout << "1) cosine + sine" << endl; cout << endl; cout << "===========================================" << endl; cout << endl; cout << "Please enter in first Num: " << endl; cin >> num1; cout << "Please enter in second Num: " << endl; cin >> num2; cout << endl; trigSum(num1,num2) return 0; } ``````
on line 59 you are missing the semicolon.
thanks. is there a program that you know of that can identify those kind of simple errors?
Yes, there are many programs. They generally fall under the category of program known as C++ Compilers. Some give you better error messages than others.
alright thanks ill look those up.

last thing: now that it compiles my answer always returns as 1, any clue why?

this is my updated code:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071`` ``````// -------------------------------------------------------------------- // File name: simpleMath.cpp // Assign ID: LAB10 // Due Date: 11/07/12 at 7:30 pm // // Purpose: Performs a simple addiion between 2 items. // // Author: bfields Byron Fields // -------------------------------------------------------------------- #include #include #include using namespace std; // ----------------------------------------------------------------- // Function Name: trigSum // Purpose: Returns a value for calculations // // Invocation: sum = trigSum(double,double); // // ----------------------------------------------------------------- double trigSum(double num1,double num2) { double sum; sum = cos(num1) + sin(num2); return sum; } int main() { double num1; double num2; cout << "(c) 2012, bfields Byron Fields" << endl; cout << endl; cout << "===========================================" << endl; cout << endl; cout << "This function calculates the sum of cosine" << endl; cout << "of 1 Number and sine of another number." << endl; cout << "The given calculation is:" << endl; cout << endl; cout << "1) cosine(Num1) + sine(Num2)" << endl; cout << endl; cout << "===========================================" << endl; cout << endl; cout << "Please enter in first Num: " << endl; cin >> num1; cout << "Please enter in second Num: " << endl; cin >> num2; cout << endl; trigSum(num1,num2); cout << "===========================================" << endl; cout << "cosine(" << num1 << ") + sine(" << num2 << ") = " << fixed << setprecision(3) << trigSum << endl; cout << "===========================================" << endl; cout << endl; cout << endl; cout << "(c) 2012, bfields Byron Fields" << endl; return 0; } ``````
try using either fixed or setprecision, but not both.

that didnt work.

compiler gives this error though:

warning: the address of `double trigSum(double, double)', will
always be `true'

End of line 62:

`<< trigSum << endl;`

You're printing a function itself, not its return value. Try removing line 59 and actuall calling the function:

`<< trigSum(num1,num2) << endl;`
Last edited on
Replace trigsum in line 62 with line 59.
that worked thanks to you all.
Topic archived. No new replies allowed.