can someone identify the error in my funtion?

I continue to get error:

1
2
3
4
 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'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// --------------------------------------------------------------------
// 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 <iostream>
#include <iomanip>
#include <cmath>
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)

    
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// --------------------------------------------------------------------
// 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 <iostream>
#include <iomanip>
#include <cmath>
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.