Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Wrong outpur help... (http://www.go4expert.com/forums/wrong-outpur-help-t24442/)

bsudhir6 8Jan2011 17:08

Wrong outpur help...
 
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 8Jan2011 17:58

Re: Wrong outpur help...
 
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



All times are GMT +5.5. The time now is 13:37.