-
problem with function
Hey,
When I run the following program, the output gives 0 for the btw. I probably made an error in typing the program, but I can't seem to find it.
Lynn
Code:
/*fbtw.c*/
#include <stdio.h>
int btw21(int x);
void main (void)
{
int faktuurbedrag,btw,inclusief;
printf("Geef het faktuurbedrag:");
scanf("%d%*c",&faktuurbedrag);
btw=btw21(faktuurbedrag);
inclusief=faktuurbedrag+btw;
printf("BTW = %5d\n",btw);
printf("inclusief btw= %5d\n",inclusief);
}
int btw21(int a)
{
int b;
b=a*0,21+0,5;
return b;
}
-
0 is the expected output for this program.
you need to use a floating point type for the calculations to get a different ( more accurate ) result.
Kurt
-
Thanks. I changed it into float, but it still gives 0.
Lynn
-
Use . for a decimal point.
[edit]And main returns an int.
-
That is because the the compiler expects '.' not ',' as decimal separator.
this are actually 3 statements
1) b=a*0
2) 21+0
3) 5
Kurt
-
This was the problem indeed. Thank you very much for solving it. :)
Lynn