Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help returning double

Status
Not open for further replies.

Maulkin

Programmer
Apr 8, 2002
19
AU
I wrote this function it should return a double but the compiler returns this error:
line 38: incorrect function return type
this is my code line 38 is the second line

Code:
double expon(int n, int m, int o, int p)
 {
 	int i;
 	double temp;
 	temp = 1;
 	for (i = 1; i < (m + 1); i++)
 	{
 		temp = temp * n;
 		if (p == 1)
 		{
 			while (temp > (double)o)
 			{
 				temp = temp - o;
 			}
 		}
 	}
 	return temp;
 }
 
i'm running winME and Miracle C Compiler (r3.2)
and this is the minimumal code.
This line creates the compiler error

----> double expon(){


Code:
#include <stdio.h>
#include <stdlib.h>

main()
{
	printf(&quot;\nreturned: %.0f&quot;, expon());

}
 
double expon(){
 	double temp;
 	temp = 1;
 	return temp;
}
 
Try declaring your function first as it looks like your compiler thinks that an INT should be returned.
double expon();
 
> i'm running winME and Miracle C Compiler (r3.2)
Figures - that compiler is a toy. It has very few library functions, and is nowhere near being an ANSI-C compiler.

Do yourself a favour and get Bloodshed DEV-C++ / Borland command line 5.5

Don't worry about the C++ tags, they contain perfectly capable C compilers as well. Just make sure you call your files
Code:
prog.c
and not
Code:
prog.cpp

Oh, and as DucatiST2 pointed out, prototype the function before calling it
Code:
#include <stdio.h>
#include <stdlib.h>

/* this is a prototype */
double expon();

int main()  /* main returns an int */
{
    printf(&quot;\nreturned: %.0f&quot;, expon());
    return 0;
}
 
double expon(){
     double temp;
     temp = 1;
     return temp;
}

--
 
thanks DucatiST2 and Salem prototyping the function worked fine. Also thanks for the advice on Dev-C++ Salem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top