I can't see where these errors are, please help.

1>c:\users\katie\documents\visual studio 2010\projects\mathematic functions\mathematic functions\mathematic functions.cpp(36): error C2059: syntax error : '('
1>c:\users\katie\documents\visual studio 2010\projects\mathematic functions\mathematic functions\mathematic functions.cpp(37): error C2143: syntax error : missing ';' before '{'
1>c:\users\katie\documents\visual studio 2010\projects\mathematic functions\mathematic functions\mathematic functions.cpp(37): error C2447: '{' : missing function header (old-style formal list?)

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
#include <iostream>
using namespace std;

float add (float& a, float& b)
{ 
return (a+b); 
}

float subtract (float& c, float& d)
{
return (c-d);
}

float multiply (float& e, float& f)
{
return (e*f);
}

float divide (float& g , float& h)
 { 
return (g/h);
}

float half (float i, float& j)
{
	i=2;
return (j/i);
}

float duplicate (float k, float& l)
{ 
	k=2;
return (l*k);
}

long double ! (long double m)
{
	if (a>1) 
long double (a* ! (a-1));
else 
	return 1;
}

int main ()
{ 
long double x;
cout << "Please enter a value";
cin >> x;
cout << x << "! is" << ! (x);
return 0;
}
Last edited on
You cannot have ! as a function name. It is the NOT operator.
Ah. still comes up with ...
"1>c:\users\katie\documents\visual studio 2010\projects\mathematic functions\mathematic functions\mathematic functions.cpp(43): warning C4715: 'factorial' : not all control paths return a value
1>c:\users\katie\documents\visual studio 2010\projects\mathematic functions\mathematic functions\mathematic functions.cpp(39): warning C4700: uninitialized local variable 'a' used"
when I changed to
1
2
3
4
5
6
7
8
long double factorial (long double m)
{
	long double a;
	if (a>1) 
long double (a* factorial (a-1));
else 
	return 1;
}
(also changed it in the other functions aswell)
Missing return on line 5?
what you mean missing return...?
I've put return on line 6... isn't that the same (or do you mean on line 5 in my reply??)
Yes, I mean your reply.
So i'm returning 'a' after or before long double (a*factorial (a-1))...?

its came up with 'illegal else without matching if' when i tried both of those...
AH!! I got it... return instead of 'long double'. Thanks guys :)
Plus: remove line 3 and rename m as a
Topic archived. No new replies allowed.