I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

Lucian I need your help! Please

dragonlady\′s Photo
19 Apr 07, 3:57AM
(1 reply)
Lucian I need your help! Please
I need this to ask for each area so it will compute the tax. I can't get it to work. Here is what I have.

Posted: Mon Apr 16, 2007 7:10 am Post subject: need help with this program

--------------------------------------------------------------------------------

I am trying to write a tax calculator, once he amount is entered for each area, my window disappears. Also, it compiles and runs in bloodshed but not miracle c. It has to be in miracle c for my class. Please help. here it is

#include <stdio.h> 
int main(void) 
{ 
 
/* sales tax (x) = item total * sales tax; DelMar sales tax, 0.0725; Encinitas sales tax, 0.075;
LaJolla sales tax, 0.0775 */; 
 
float taxDelMar, taxEncinitas, taxLaJolla; 
float saleDelMar, saleEncinitas, saleLaJolla; 
float price; 
float rate1, rate2, rate3; 
rate1 = .0725; 
rate2 = .075; 
rate3 = .0775; 
 
 
/*Enter any price */ 
printf("Enter Price DelMar"); 
scanf("%f", &amp;price); 
printf("Enter Price Encinitas"); 
scanf("%f", &amp;price); 
printf("Enter Price LaJolla"); 
scanf("%f", &amp;price); 
 
/* Calculate Sales Tax and Total Sale Amount for DelMar */ 
taxDelMar = rate1 * price; 
printf("Sales tax DelMar is $%.2f\n", taxDelMar); 
saleDelMar = taxDelMar + price; 
printf("Total Sale Amount DelMar is $%.2f\n", saleDelMar); 
 
/* Calculate Sales Tax and Total Sale Amount for Encinitas */ 
taxEncinitas = rate2 * price; 
printf("Sales tax Encinitas is $%.2f\n", taxEncinitas); 
saleDelMar = taxDelMar + price; 
printf("Total Sale Amount Encinitas is $%.2f\n", saleEncinitas); 
 
/* Calculate Sales Tax and Total Sale Amount for LaJolla */ 
taxLaJolla = rate3 * price; 
printf("Sales tax LaJolla is $%.2f\n", taxLaJolla); 
saleLaJolla = taxLaJolla + price; 
printf("Total Sale Amount LaJolla is $%.2f\n", saleLaJolla); 
 
return 0; 
 
}

Thanks :( :? :oops:

lucian\′s Photo
23 Apr 07, 5:10PM
Hi there! Here is my solution to your problem.

First of all you need to remove the ; character at the end of this line:

/* sales tax (x) = item total * sales tax; DelMar sales tax, 0.0725; Encinitas sales tax, 0.075;
LaJolla sales tax, 0.0775 */;

Then what you need to do is add this line at the end of the main() function, right before the "return 0;" part

while (!kbhit());

It waits for you to press any key before closing the window.

So in the end your code should look something like this:
#include <stdio.h> 
 
int main(void) 
{ 
/* sales tax (x) = item total * sales tax; DelMar sales tax, 0.0725; Encinitas sales tax, 0.075;
LaJolla sales tax, 0.0775 */ 
 
float taxDelMar, taxEncinitas, taxLaJolla; 
float saleDelMar, saleEncinitas, saleLaJolla; 
float price; 
float rate1, rate2, rate3; 
rate1 = .0725; 
rate2 = .075; 
rate3 = .0775; 
 
/*Enter any price */ 
printf("Enter Price DelMar"); 
scanf("%f", &price); 
printf("Enter Price Encinitas"); 
scanf("%f", &price); 
printf("Enter Price LaJolla"); 
scanf("%f", &price); 
 
/* Calculate Sales Tax and Total Sale Amount for DelMar */ 
taxDelMar = rate1 * price; 
printf("Sales tax DelMar is $%.2f\n", taxDelMar); 
saleDelMar = taxDelMar + price; 
printf("Total Sale Amount DelMar is $%.2f\n", saleDelMar); 
 
/* Calculate Sales Tax and Total Sale Amount for Encinitas */ 
taxEncinitas = rate2 * price; 
printf("Sales tax Encinitas is $%.2f\n", taxEncinitas); 
saleDelMar = taxDelMar + price; 
printf("Total Sale Amount Encinitas is $%.2f\n", saleEncinitas); 
 
/* Calculate Sales Tax and Total Sale Amount for LaJolla */ 
taxLaJolla = rate3 * price; 
printf("Sales tax LaJolla is $%.2f\n", taxLaJolla); 
saleLaJolla = taxLaJolla + price; 
printf("Total Sale Amount LaJolla is $%.2f\n", saleLaJolla); 
 
while (!kbhit()); 
 
return 0; 
}

I've compiled it using Miracle C and also have tried executing the code. It seems to work well. Let me know if you have any more trouble.

I hope my solution didn't come too late.
Currently you need to be logged in to leave a message.