In this code compiler says "type mismatch" in function. There are two diff data type in function one int and one Float. Is it possible to use two diff values or i need to take both of same type. plz rply

Thanks

#include<stdio.h>
#include<conio.h>

void main()
{
	int a;
	float b=5.5,multiply;

	clrscr();
	printf("Enter the int");
	scanf("%d",&a);

	printf("Enter the float");
	scanf("%f",&b);

	multiply=prod(a,b);

	printf("%f",multiply);

	getch();

}

prod(int x,float y)
{

	float product;

	  product=x*y;
      
	  return(product);


}

You didn't show a return type for the prod() function. Also, you didn't add the prototype to the function, before main().

The prototype is just like the first line of the function, but doesn't need the name of the variables, just the type. Put that below the include files, before main().

Your compiler will WUVE YOU! ;) ;)

Edited 5 Years Ago by Adak: n/a

do you want me to write line 32 as "return(float product)" .......... and prototype as
"float prod()" above main.............

plz rply

float prod() is not a prototype, it's merely a declaration. float prod(int, float) is a prototype.

As you have it declared, prod() returns int. You'll need to declare it otherwise in order to use it the way you want to.

Also, the usual: <conio.h> is obsolete and nonstandard, main returns int, use fflush(stdout) after printing a prompt without \n, don't use scanf() for interactive input, and your liberal use of whitespace is quite distracting.

Thanks for teh reply Trentacle.

The program run perfectly. but still i m not knowing, wht to use if not using conio.h (as it has prototype for getch()) as well i think compiler itself flushes memory for me, do i really have to explicitly write ffluch().......and what does "stdout" meant for

I know too many questions..........but plzzzzzzzz answer me......
Thanks

If you absolutely have to, use getchar(), which is declared in <stdio.h>. But if you take my advice, you'll just leave it off and run your program in such a way that you can read the output after the program has exited.

fflush(stdout) is necessary to make sure the prompt gets printed on systems that perform line buffering. Since you don't have a \n on the end of your prompt, it might not appear when you want it to, giving the impression that your program has hung when it's actually just waiting for input.

main returns int, not void.

Finally, since you don't check the return value of scanf(), you invoke undefined behavior when the user inputs non-numeric data. For a one-off program, it's not a big deal, but you should be in the habit of checking the return values of all standard library functions.

Yes you can use two different datatypes while calling a function and try by using the return type int in the function

This article has been dead for over six months. Start a new discussion instead.