Function problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream.h>
int	function2.7(int a,int b)
	{int i=1;int power=1;
     power=power*a;
     cout<<"power="<<power;
     i+=i;
     cout<<"i="<<i;
     if(i<y)
	   cout<<"i is smaller than y";
     else 
	   cout<<"i is bigger than y";
	 return 0;}
void main()
{
	//exercise 2.7
	int x,y;
	cout<<"input 2 numbers for x y:";
	cin>>x>>y;
	function2.7(x,y);
}


The code always gives error:
error C2143: syntax error : missing ';' before 'constant'
fatal error C1004: unexpected end of file found
Error executing cl.exe.

I can't find out where the wrong code is.
closed account (z05DSL3A)
The function name should not have a . in it.

Change it to somthing like
1
2
int	function2_7(int a,int b)
{...


What compiler/IDE are you using? If it is old then #include<iostream.h> may not cause a problem, but if it is new than the include should be #include<iostream> (i.e. drop it .h) this would also mean that you would have to scope cout and such with std:: (i.e. std::cout << ... ) or use using namespace std; .

It also looks like line 8 should be if(i<b) and line 13 should be int main().
Last edited on
thanks for reply.
My complier is vc++6.0.
If 13 changes into int main(),there will be a warning:
1
2
function should return a value; 'void' return type assumed
Linking...
closed account (z05DSL3A)
VC6 is old.

Sorry, forgot to mention that a return statement would be needed for int main. void main is not standard (but then again VC6 does not follow standards very much).

1
2
3
4
5
int main()
{
    ...
    return 0;
}


Unless you have a pressing reason for using VC6, I would recommend getting an more up to date compiler/IDE.
Last edited on
Topic archived. No new replies allowed.