[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

program not performing functions

Posted on 2006-03-23
8
Medium Priority
?
297 Views
Last Modified: 2010-04-17
I am writing a program to take a users input from the screen and calculate a tax amount  on the input. I compile my program with no errors and when run it and enter a price it does not calculate the amount. I have the tax amount coded and for some reason it picks the tax up as 0 and the calculation is not right. I have the code below. What am i doing wrong?


#include <stdio.h>
int main()
{      
/*     // declare variables here*/
//The first variables are each stores tax rate, Del Mar, Encinitas, La jolla
//The second variable is the purchase amount
//The third variable is the calculated tax rate
//The fourth variable is for user input of purchase amount
       float fDelMarTaxRate = 7.25;
       float fEncinitasTaxRate = 7.5;
       float fLaJollaTaxRate = 7.75;
       float fPurchaseAmount;
       float fDelMarSalesTax, fEncinitasSalesTax, fLaJollaSalesTax;
       float fpurchase;
       float fDelMarTotal;
       float fEncinitasTotal;
       float fLaJollaTotal;

//print message asking what the purchase amount is
    printf("What is the purchase amount?");

/*imput the answer into purchase*/
   scanf("%d,&fpurchase");


/*calculate the tax amount*/
   fDelMarSalesTax =((fDelMarTaxRate/100)*fpurchase);
   fEncinitasSalesTax = ((fEncinitasTaxRate/100)*fpurchase);
   fLaJollaSalesTax = ((fLaJollaTaxRate/100)*fpurchase);

 
/*calculate the total*/
   fDelMarTotal=(fpurchase+fDelMarSalesTax);
   fEncinitasTotal=(fpurchase+fEncinitasSalesTax);
   fLaJollaTotal=(fpurchase+fLaJollaSalesTax);

/* print the total*/
  printf("\n Del Mar Total %.2f\n"),fDelMarTotal;
  printf("\n Encinitas Total %.2f\n"),fEncinitasTotal;
  printf("\n La Jolla Total %.2f\n"),fLaJollaTotal;         
   
/*//     Return zero to confirm that the program ran*/
     return 0;
}
0
Comment
Question by:pgmtkl
  • 4
  • 4
8 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16272539
  scanf("%d,&fpurchase");

should be

   scanf("%f",&fpurchase);
0
 

Author Comment

by:pgmtkl
ID: 16272632
Thanks. That still returns all the totals to the screen as 0.00. Is there something else i am missing? I am taking the scan purchase amount and calculate the tax amount, then adding that to the input purchase amount. It still gives me 0.00.
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16272738
Misplaced parenthesis:

  printf("\n Del Mar Total %.2f\n",fDelMarTotal);
  printf("\n Encinitas Total %.2f\n",fEncinitasTotal);
  printf("\n La Jolla Total %.2f\n",fLaJollaTotal);        
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:pgmtkl
ID: 16272789
Thanks. I corrected that. But it still displays 0.00 for all 3 totals. DO i have the calculation coded wrong?
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 2000 total points
ID: 16272830
This is working fine for me:


#include <stdio.h>
int main()
{      
/*     // declare variables here*/
//The first variables are each stores tax rate, Del Mar, Encinitas, La jolla
//The second variable is the purchase amount
//The third variable is the calculated tax rate
//The fourth variable is for user input of purchase amount
       float fDelMarTaxRate = 7.25;
       float fEncinitasTaxRate = 7.5;
       float fLaJollaTaxRate = 7.75;
       float fPurchaseAmount;
       float fDelMarSalesTax, fEncinitasSalesTax, fLaJollaSalesTax;
       float fpurchase;
       float fDelMarTotal;
       float fEncinitasTotal;
       float fLaJollaTotal;

//print message asking what the purchase amount is
    printf("What is the purchase amount?");

/*imput the answer into purchase*/
   scanf("%f",&fpurchase);


/*calculate the tax amount*/
   fDelMarSalesTax =((fDelMarTaxRate/100)*fpurchase);
   fEncinitasSalesTax = ((fEncinitasTaxRate/100)*fpurchase);
   fLaJollaSalesTax = ((fLaJollaTaxRate/100)*fpurchase);

 
/*calculate the total*/
   fDelMarTotal=(fpurchase+fDelMarSalesTax);
   fEncinitasTotal=(fpurchase+fEncinitasSalesTax);
   fLaJollaTotal=(fpurchase+fLaJollaSalesTax);

/* print the total*/
  printf("\n Del Mar Total %.2f\n",fDelMarTotal);
  printf("\n Encinitas Total %.2f\n",fEncinitasTotal);
  printf("\n La Jolla Total %.2f\n",fLaJollaTotal);        
   
/*//     Return zero to confirm that the program ran*/
     return 0;
}
0
 

Author Comment

by:pgmtkl
ID: 16272980
Thank you so much. I have been stuck on this one item and when just compared the program I found my error. I had  misplaced the quotes on the scan input line. i had scanf("%f,&fpurchase"); instead of scanf("%f",fpurchase).  Thank you for your help.
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16273111
That's what I told in my first comment :)

Thanks
0
 

Author Comment

by:pgmtkl
ID: 16273794
I must of overlooked that. I have been stuck on this one item. thanks again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question