Thread: I Have A Questio here

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    7

    I Have A Questio here

    Why I can't print out the change due with my coding?anyone can solve it to me?
    Code:
    #include<stdio.h>
    #include<math.h>
    
    void main()
    {
    	int discount,set_of_combo;
    	double total,a_payable,amount,cash;
    	double g_tax,s_tax,change_due,a_a_payable;
    
    	printf("Enter Number Of Combo Set : ");
    	scanf("%d",&set_of_combo);
    
    	printf("Enter Discount Voucher (RM) : ");
    	scanf("%d",&discount);
    
    	//calculation
    	amount = set_of_combo*7.88;
    	g_tax = amount * 6 / 100;
    	s_tax = amount *10 / 100;
    	total = g_tax + s_tax + amount;
    	a_payable = total - discount;
    	a_a_payable = a_payable;
            change_due = cash - a_a_payable
    
    	printf("Good Day and Welcome To KLFC Sdn.Bhd");
    
    	printf("R E C E I P T\n");
    	printf("+-------------------------+------------------+-------------------+\n");
    	printf("+       Description       |       Rate       |     Amount(RM)    |\n");
    	printf("+-------------------------+------------------+-------------------+\n");
    	printf("+      COMBO SET * %d      |       7.88       |        %.2f      |\n",set_of_combo,amount);
    	printf("+      Goverment Tax      |        6%%        |        %.2f       |\n",g_tax);
    	printf("+      Service Tax        |        10%%       |        %.2f       |\n",s_tax);
    	printf("+-------------------------+------------------+-------------------+\n");
    	printf("+               S U B   T O T A L            |          %.2f    |\n",total);
    	printf("+============================================+===================|\n");
    	printf("+      Discount Vouvher (RM)  %.2lf                               +\n",discount);//discount voucher
    	printf("+                           --------                             |\n");
    	printf("+      Amount Payable         %.2lf                              |\n",a_payable);//amount payable
    	printf("+                           ========                             |\n");
    	printf("+      Adjusted Amount Payable                      %.2lf          |\n",a_a_payable);//adjustment amount payable
    	printf("=================================================================+\n");
    	printf(" CASH ");
    	scanf("%.2lf",&cash);
    	printf(" Change Due:\n",change_due);
    	printf("==================================================================\n");
    	printf("               THANK YOU and HAVE A NICE DAY\n");
    
    }
    Last edited by tokipatrick; 06-10-2011 at 07:41 AM. Reason: font size/style abuse

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Presumably because you don't do

    change_due = some_expression_involving_cash_and_amount_due;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    7
    i changed...the out come like this..

    Enter Number Of Combo Set : 4
    Enter Discount Voucher (RM) : 2
    Good Day and Welcome To KLFC Sdn.BhdR E C E I P T
    +-------------------------+------------------+-------------------+
    + Description | Rate | Amount(RM) |
    +-------------------------+------------------+-------------------+
    + COMBO SET * 4 | 7.88 | 31.52 |
    + Goverment Tax | 6% | 1.89 |
    + Service Tax | 10% | 3.15 |
    +-------------------------+------------------+-------------------+
    + S U B T O T A L | 36.56 |
    +============================================+==== ===============|
    + Discount Vouvher (RM) 0.00 +
    + -------- |
    + Amount Payable 34.56 |
    + ======== |
    + Adjusted Amount Payable 34.56 |
    ================================================== ===============+
    CASH 44
    Change Due:
    ================================================== ================
    THANK YOU and HAVE A NICE DAY
    Press any key to continue

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    7
    Quote Originally Posted by Salem View Post
    Presumably because you don't do

    change_due = some_expression_involving_cash_and_amount_due;
    i changed...the out come like this..

    Enter Number Of Combo Set : 4
    Enter Discount Voucher (RM) : 2
    Good Day and Welcome To KLFC Sdn.BhdR E C E I P T
    +-------------------------+------------------+-------------------+
    + Description | Rate | Amount(RM) |
    +-------------------------+------------------+-------------------+
    + COMBO SET * 4 | 7.88 | 31.52 |
    + Goverment Tax | 6% | 1.89 |
    + Service Tax | 10% | 3.15 |
    +-------------------------+------------------+-------------------+
    + S U B T O T A L | 36.56 |
    +============================================+==== ===============|
    + Discount Vouvher (RM) 0.00 +
    + -------- |
    + Amount Payable 34.56 |
    + ======== |
    + Adjusted Amount Payable 34.56 |
    ================================================== ===============+
    CASH 44
    Change Due:
    ================================================== ================
    THANK YOU and HAVE A NICE DAY
    Press any key to continue

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So show us what you did to the code.

    And don't forget, you need a format conversion in the print statement as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    7
    Quote Originally Posted by Salem View Post
    So show us what you did to the code.

    And don't forget, you need a format conversion in the print statement as well.
    what did you mean?

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    printf(" Change Due:\n",change_due);
    Do you expect this to print a number? Why?

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    7
    Quote Originally Posted by tabstop View Post
    Code:
    printf(" Change Due:\n",change_due);
    Do you expect this to print a number? Why?
    ya..>.<...because above the statement also use this way to print out..anything wrong with it?

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by tokipatrick View Post
    ya..>.<...because above the statement also use this way to print out..anything wrong with it?
    You really really need to learn to read a little better. Compare that statement with the "above statement" that works and notice the difference.

  10. #10
    Registered User
    Join Date
    Jun 2011
    Posts
    7
    Quote Originally Posted by tabstop View Post
    You really really need to learn to read a little better. Compare that statement with the "above statement" that works and notice the difference.
    i am blur with it..>.<..i am sorry,i still new with C++ language...

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by tokipatrick View Post
    i am blur with it..>.<..i am sorry,i still new with C++ language...
    That's okay, you're not writing C++. Anyway, do you know how to print a number?

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    7
    Quote Originally Posted by tabstop View Post
    That's okay, you're not writing C++. Anyway, do you know how to print a number?
    you mean after the calculation?

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by tokipatrick View Post
    you mean after the calculation?
    I mean at all. Do you know how to print any kind of number?

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    As in,

    why do you think this line prints a value,
    printf("+ Adjusted Amount Payable %.2lf |\n",a_a_payable);//adjustment amount payable

    and this one doesn't
    printf(" Change Due:\n",change_due);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Wrong forum? Are you really trying to learn C++?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed