Wrong outpur help...

bsudhir6's Avatar, Join Date: Apr 2010
Go4Expert Member
Code:
/*Calculates the total sale given the unit price, quantity, discount,
    and tax rate
    @author: Sudhir
    @Date and time: 1/8/2011 4:04:06 PM
*/
#include<stdio.h>

#define TAX_RATE 8.50

int main(int argc,char *argv[])
{
    //Local Declarations
    int quantity;

    float discountRate;
    float discountAm;
    float unitPrice;
    float subTotal;
    float subTaxable;
    float taxAm;
    float total;

    //Statements
    printf("\n Enter number of items sold:            ");
    scanf("%d", &quantity);

    printf("\n Enter the discount rate(per cent):            ");
    scanf("%d", &discountRate);

    printf("\n Enter the unit price:            ");
    scanf("%d", &unitPrice);



    subTotal = quantity * unitPrice;
    discountAm = subTotal * discountRate / 100.0;
    subTaxable = subTotal - discountAm;
    taxAm = subTaxable * TAX_RATE / 100.0;
    total = subTaxable + taxAm;

    printf("\n quantity sold:    %6d \n",quantity);
    printf("Unit Price of items: %9.2f \n",unitPrice);
    printf("                --------\n");

    printf("Subtotal : %9.2f\n", subTotal);
    printf("Discount : %9.2f\n", discountAm);
    printf("Discounted total : %9.2f\n", subTaxable);
    printf("Sales tax: %9.2f\n", taxAm);
    printf("Total : %9.2f\n", total);

    return 0;
}//main
The output coming to me is....
Code:
 Enter number of items sold:                    34

 Enter the discount rate(per cent):                     7

 Enter the unit price:                  12.89

 quantity sold:     34
Unit Price of items:      0.00
                                --------
Subtotal :      0.00
Discount :      0.00
Discounted total :      0.00
Sales tax:      0.00
Total :      0.00
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Code:
/*Calculates the total sale given the unit price, quantity, discount,
    and tax rate
    @author: Sudhir
    @Date and time: 1/8/2011 4:04:06 PM
*/
#include<stdio.h>

#define TAX_RATE 8.50

int main(int argc,char *argv[])
{
    //Local Declarations
    int quantity;

    float discountRate;
    float discountAm;
    float unitPrice;
    float subTotal;
    float subTaxable;
    float taxAm;
    float total;

    //Statements
    printf("\n Enter number of items sold:            ");
    scanf("%d", &quantity);getchar();

    printf("\n Enter the discount rate(percent):            ");
    scanf("%f", &discountRate);getchar();

    printf("\n Enter the unit price:            ");
    scanf("%f", &unitPrice);getchar();



    subTotal = (float) quantity * unitPrice;
    discountAm = subTotal * discountRate / 100.0;
    subTaxable = subTotal - discountAm;
    taxAm = (float) subTaxable * TAX_RATE / 100.0;
    total = subTaxable + taxAm;

    printf("\n quantity sold:    %6d \n",quantity);
    printf("Unit Price of items: %9.2f \n",unitPrice);
    printf("                --------\n");

    printf("Subtotal : %9.2f\n", subTotal);
    printf("Discount : %9.2f\n", discountAm);
    printf("Discounted total : %9.2f\n", subTaxable);
    printf("Sales tax: %9.2f\n", taxAm);
    printf("Total : %9.2f\n", total);
    getchar();
    return 0;
}//main