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
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([COLOR=Red]percent[/COLOR]): "); scanf("%[COLOR=Red]f[/COLOR]", &discountRate);[COLOR=Red]getchar();[/COLOR] printf("\n Enter the unit price: "); scanf("%[COLOR=Red]f[/COLOR]", &unitPrice);[COLOR=Red]getchar();[/COLOR] subTotal = [COLOR=Red](float)[/COLOR] quantity * unitPrice; discountAm = subTotal * discountRate / 100.0; subTaxable = subTotal - discountAm; taxAm = [COLOR=Red](float)[/COLOR] 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); [COLOR=Red]getchar();[/COLOR] return 0; }//main