Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Purchase

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Malaysia
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Purchase

    Dear sir,

    Why the tax1 variable can't be converted?
    How can I make the amounts into currency format?

    #include <stdio.h>
    main()
    {
    int qty_sundae;
    int qty_meals;
    int qty_extra;
    float sundae = 1.05;
    float meal = 4.50;
    float extra = 6.10;
    float amount1;
    float amount2;
    float amount3;
    float tax1;

    printf("Enter no. of sundae cones : ");
    scanf("%d", &qty_sundae);
    printf("Enter no. of Happy meals : ");
    scanf("%d", &qty_meals);
    printf("Enter no. of Extra Value Meal : ");
    scanf("%d", &qty_extra);

    printf("\nWelcome to MC Donald's \n");
    printf("Your Bill, \n");

    amount1=qty_sundae*sundae;
    amount2=qty_meals*meal;
    amount3=qty_extra*extra;
    printf("\t %d Sundae cones \t :RM %f \n", qty_sundae, amount1);
    printf("\t %d Happy meals \t\t :RM %f \n", qty_meals, amount2);
    printf("\t %d Extra value meals \t :RM %f \n", qty_extra, amount3);

    tax1=((amount1+amount2+amount3)/100)*5;
    printf("\t 5% Service Tax \t :RM %f \n", tax1);
    printf("\nTotal Charges\t\t\t :RM %f \n", amount1 + amount2 + amount3 + tax1);
    return 0;
    }

    Thanks

    Xiang

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use %.2f

    Will cause the number to only use 2 decimal spaces. I'm not sure if it automatically rounds. If it doesn't, just add .005 to the ammount
    Last edited by Josh Campbell; 12-31-2002 at 03:25 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •