int main()
{
int a, b, c;
printf("Enter a numerator: ");
scanf("%d", &a);
printf("Enter a denominator: ");
scanf("%d", &b);
c=add(a,b);
printf("%f",c);
}
int add(int a, int b)
{
return(a/b);
}
How come the result is always in 0.0000 value?
Where can I put system("pause"); in this function?
0 is due to integer division. int/int = int, so normally 3/4 = 0.75 but (since integers round down) 0.75 becomes 0.
you could return a/(float)b; or have a and b float from the beginning.
you'd put system("pause") before returning from main (which you don't do. how can you have an int function that doesn't return an int? ) though you shouldn't use system at all. ( http://www.cplusplus.com/forum/articles/11153/ ). use getchar() or something..