i'm new to the C language, so i was trying to do this piece of code that add the quantity of all items purchased, the subTotal, and the salesTax. However, i can't seem to figure out why the code is jumping to the third item and doing this calculation only. I know that something is being done wrong, i just cannnot seem to figure it out.
[code]
#include #include int main () {
double tvPrice = 400.00;
double vcrPrice = 220.00;
double remoteControlPrice = 35.20;
double cdPlayerPrice = 300.00;
double tapeRecorderPrice = 150.00;
const double tax = 0.0825;
int quantity = 0;
double subTotal = 0;
double total = 0, salesTax;
printf("How Many TV's Were Sold? ");
scanf("%d", &quantity);
subTotal = quantity * tvPrice;
printf("How Many VCR's Were Sold? ");
scanf("%d", &quantity);
printf("How Many Remote Controllers Were Sold? ");
scanf("%d", &quantity);
total = subTotal + tax;
total = subTotal + tax;
printf("How Many CD's Were Sold? ");
scanf("%d", &quantity);
printf("How Many Tape Recorders Were Sold? ");
scanf("%d", &quantity);
subTotal = quantity * tvPrice;
//subTotal = quantity * vcrPrice;
//subTotal = quantity * remoteControlPrice;
//subTotal = quantity * cdPlayerPrice;
//subTotal = quantity * remoteControlPrice;
salesTax = subTotal * tax;
total = subTotal + salesTax;
printf ("%6s%18s%18s%20s
", "QTY", "DESCRIPTION", "UNIT PRICE","TOTAL PRICE");
printf ("---------------------------------------------------------------
");
printf ("%6d%18s%16.2lf%18.2lf
",quantity,"TV",tvPrice,subTotal);
printf ("%6d%18s%16.2lf%18.2lf
",quantity,"VCR",vcrPrice,subTotal);
printf ("%6d%18s%16.2lf%18.2lf
",quantity,"REMOTE CTRLR",remoteControlPrice,total);
printf ("%6d%18s%16.2lf%18.2lf
",quantity,"CD PLAYER",cdPlayerPrice,total);
printf ("%6d%18s%16.2lf%18.2lf
",quantity,"TAPE RECORDER",tapeRecorderPrice,total);
printf(" SUBTOTAL: %10.2lf
", subTotal);
printf(" TAX: %10.2lf
", salesTax);
printf(" TOTAL: %10.2lf
", total);
system("pause");
return 0;
}
[/code]
Comments
Take Care,
Ed
thanks
hens
[code]
#include
#include
int main () {
double tvPrice = 400.00;
double vcrPrice = 220.00;
double remoteControlPrice = 35.20;
double cdPlayerPrice = 300.00;
double tapeRecorderPrice = 150.00;
const double tax = 0.0825;
int quantitytv = 0, quantityvcr = 0, quantityrem = 0, quantitycd = 0, quantityrec = 0;
double subTotal = 0;
double total = 0, salesTax;
printf("How Many TV's Were Sold? ");
scanf("%d", &quantitytv); //[red]changed quantity[/red]
[red]//[/red] subTotal = quantity * tvPrice;
printf("How Many VCR's Were Sold? ");
scanf("%d", &quantityvcr); //[red]changed quantity[/red]
printf("How Many Remote Controllers Were Sold? ");
scanf("%d", &quantityrem); //[red]changed quantity[/red]
[red]//[/red] total = subTotal + tax;
[red]//[/red] total = subTotal + tax;
printf("How Many CD's Were Sold? ");
scanf("%d", &quantitycd); //[red]changed quantity[/red]
printf("How Many Tape Recorders Were Sold? ");
scanf("%d", &quantityrec); //[red]changed quantity[/red]
subTotal = quantitytv * tvPrice;
subTotal += quantityvcr * vcrPrice;
subTotal += quantityrem * remoteControlPrice;
subTotal += quantitycd * cdPlayerPrice;
subTotal += quantityrec * tapeRecorderPrice;
salesTax = subTotal * tax;
total = subTotal + salesTax;
printf ("%6s%18s%18s%20s
", "QTY", "DESCRIPTION", "UNIT PRICE","TOTAL PRICE");
printf ("---------------------------------------------------------------
");
printf ("%6d%18s%16.2lf%18.2lf
",quantitytv,"TV",tvPrice,quantitytv * tvPrice);
printf ("%6d%18s%16.2lf%18.2lf
",quantityvcr,"VCR",vcrPrice,quantityvcr * vcrPrice);
printf ("%6d%18s%16.2lf%18.2lf
",quantityrem,"REMOTE CTRLR",remoteControlPrice,quantityrem * remoteControlPrice);
printf ("%6d%18s%16.2lf%18.2lf
",quantitycd,"CD PLAYER",cdPlayerPrice,quantitycd * cdPlayerPrice);
printf ("%6d%18s%16.2lf%18.2lf
",quantityrec,"TAPE RECORDER",tapeRecorderPrice,quantityrec * tapeRecorderPrice);
printf(" SUBTOTAL: %10.2lf
", subTotal);
printf(" TAX: %10.2lf
", salesTax);
printf(" TOTAL: %10.2lf
", total);
system("pause");
return 0;
}
[/code]
Take Care,
Ed