Thread: problem with function

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    6

    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;
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    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

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    6
    Thanks. I changed it into float, but it still gives 0.

    Lynn

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Use . for a decimal point.

    [edit]And main returns an int.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    That is because the the compiler expects '.' not ',' as decimal separator.
    Code:
    b=a*0,21+0,5;
    this are actually 3 statements
    1) b=a*0
    2) 21+0
    3) 5

    Kurt

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    6
    This was the problem indeed. Thank you very much for solving it.

    Lynn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM