program giving error

I made this program and its not working , Can someone tell me what is wrong with it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;
unknown(int x)
{  
	int result;
		int y=2;
	if (x>=6)
		return 1;
	else
		result=unknown(x+2)*y;
	return result;
}

int main()
{
	cout<<unknown(1);
	return 0;
}



Here is the error


1
2
3
4
5
6
Compiling...
fsdfa.cpp
c:\users\tukhi\desktop\dynamic memory allocation\sfdgsd\fsdfa.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Build log was saved at "file://c:\Users\Tukhi\Desktop\dynamic memory allocation\sfdgsd\Debug\BuildLog.htm"
sfdgsd - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
you need to give your 'unknown' function a return type. Apparently you want it to return an int, so declare it like so:

1
2
3
4
int unknown(int x)
{
  // blah
}
Did you read the error message?
missing type specifier

As the error message clearly states, the function unknown is missing the return type. This is not legal in C++.
Seeing as you're returning 'result', which is an int, unknown() should probably return an int:
int unknown(int x)
but it is returning a int and the function is int too.
result is int.
For the compiler, it's not enough for the function to return an int variable. The return type has to be declared.
How about you try it instead of arguing with someone who knows more than you?
But Sir , I know that you know more than me.you dont have to remind me that.
How can I try it when I dont know what you are saying.

return type is int.
and it is declared.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;
unknown(int x)
{  
	int result;   //return type is declared.
		int y=2;
	if (x>=6)
		return 1;
	else
		result=unknown(x+2)*y;
	return result;
}

int main()
{
	cout<<unknown(1);
	return 0;
}
Last edited on
return type is int.
and it is declared.
I just told you it's not declared, and the compiler is telling you too.

1
2
3
4
using namespace std; //<- semicolon here, so no more tokens
//v only function name. No type.
unknown(int x)
//       ^ this is not the return type. 

WHERE is it declared?
Last edited on
hahaha
sorry sir
i got it
you are great
i dont know how i made this silly mistake,
Last edited on
Topic archived. No new replies allowed.