Avatar of nolte1964
nolte1964
 asked on

Sales Calculator - UOP

I can get the code to correctly compile and as long as the user enters the purchase amount of 125.00 it will calculate correctly.  What I am having problems understanding is how to write the code so it allows the user to enter any purchase amount and cacluate that value correctly against the sales tax for each city.

This is a homework assisgnment so I am looking for a example or anything to help me figure out this coding issue.  Thank you.
//	Service Request:  SR-kf-008 Tax Calculator
//	Week 4  
//	Class:  CSS561
//	Team B
//      Change Request 1.2, Created 03-02-2009
//	Author: Mark A Nolte
 
//      Create a Sales Tax Calculator for Kudler Fine Foods
 
#include <stdio.h>
 
//      Declare a float variable for tax rate, purchase amount, total purchase amount, and sales tax
 
        float fDelMarSalesTaxRate, fEncinitasSalesTaxRate, fLaJollaSalesTaxRate;      
        float fDelMarSalesTax, fEncinitasSalesTax, fLaJollaSalesTax;
        float fDelMarSalesAmount, fEncinitasSalesAmount, fLaJollaSalesAmount;
        float fPurchaseAmount;
 
//      Declare the starting point
 
int main()
{
 
//      Set Local Sales Tax Rates
 
        fDelMarSalesTaxRate = .0725;
        fEncinitasSalesTaxRate = .075;
        fLaJollaSalesTaxRate = .0775;
        
//      Set Purchase Amount
 
        fPurchaseAmount = 125.00;
        
//      Initialize purchase amount in dollars
 
    
	printf("\n                *************************************\n");
	printf("\n                **                                 **\n");
	printf("\n                **       Kudler Tax Calculator     **\n");
	printf("\n                **                                 **\n");
	printf("\n                *************************************\n\n\n");
	printf("     How much was your purchase?  $");
	scanf(" $%.2f", &fPurchaseAmount);
	
        
//      Calculate sales tax for Del Mar, Encinitas, La Jolla in dollars
 
       fDelMarSalesTax = fPurchaseAmount * fDelMarSalesTaxRate;
       fEncinitasSalesTax = fPurchaseAmount * fEncinitasSalesTaxRate;
       fLaJollaSalesTax = fPurchaseAmount * fLaJollaSalesTaxRate;     
      
//	Calculate Total Sales Amount for Del Mar	
 
       fDelMarSalesAmount = fPurchaseAmount + fDelMarSalesTax;            
       fEncinitasSalesAmount = fPurchaseAmount + fEncinitasSalesTax;  
       fLaJollaSalesAmount = fPurchaseAmount + fLaJollaSalesTax;
            
//      Display Sales Tax for Del Mar, Encinitas, La Jolla on the Purchase Amount
 
       printf("\n\n              Purchase Amount      Sales Tax     Total Sales Amount\n");
       printf("              _______________      _________     __________________\n\n");
       printf("\n   Del Mar         $%.2f            $%.2f            $%.2f\n",fPurchaseAmount, fDelMarSalesTax, fDelMarSalesAmount);
       printf("\n   Encinitas       $%.2f            $%.2f            $%.2f\n",fPurchaseAmount, fEncinitasSalesTax, fEncinitasSalesAmount);
       printf("\n   La Jolla        $%.2f            $%.2f            $%.2f\n",fPurchaseAmount, fLaJollaSalesTax, fLaJollaSalesAmount);   
 
       getchar();
      
//      Return zero to confirm that the program ran
       return 0;
}

Open in new window

Programming Languages-OtherC

Avatar of undefined
Last Comment
nolte1964

8/22/2022 - Mon
masheik

hi,
1.remove the line fPurchaseAmount = 125.00; which sets the value to always be 125.00
2.you should not use like" $%.2f " in scanf why is $ symbol?
3. scanf help link http://www.geocities.com/learnprogramming123/Clesson4Beginner.htm
nolte1964

ASKER
Okay I removed the line fPurchaseAmount = 125.00 but of course now it doesn't return any value.  The more I read on this the more I am getting confused.

So if I don't set any value for fPurchaseAmount, how to I allow the user to enter a number that the code will process?  

//      Service Request:  SR-kf-008 Tax Calculator
//      Week 4  
//      Class:  CSS561
//      Team B
//      Change Request 1.2, Created 03-02-2009
//      Author:
 
//      Create a Sales Tax Calculator for Kudler Fine Foods
 
#include <stdio.h>
 
//      Declare a float variable for tax rate, purchase amount, total purchase amount, and sales tax
       
        float fDelMarSalesTax, fEncinitasSalesTax, fLaJollaSalesTax;
        float fDelMarSalesAmount, fEncinitasSalesAmount, fLaJollaSalesAmount;
        float fPurchaseAmount;
 
//      Declare the starting point
 
int main()
{
 
//      Set Local Sales Tax Rates
 
        #define fDelMarSalesTaxRate .0725
        #define fEncinitasSalesTaxRate .075
        #define fLaJollaSalesTaxRate .0775        
       
//      Initialize purchase amount in dollars
 
   
      printf("\n                *************************************\n");
      printf("\n                **                                 **\n");
      printf("\n                **       Kudler Tax Calculator     **\n");
      printf("\n                **                                 **\n");
      printf("\n                *************************************\n\n\n");
      printf("     How much was your purchase?  $");
      scanf("%.2f", &fPurchaseAmount);      
       
//      Calculate sales tax for Del Mar, Encinitas, La Jolla in dollars
 
       fDelMarSalesTax = fPurchaseAmount * fDelMarSalesTaxRate;
       fEncinitasSalesTax = fPurchaseAmount * fEncinitasSalesTaxRate;
       fLaJollaSalesTax = fPurchaseAmount * fLaJollaSalesTaxRate;    
     
//      Calculate Total Sales Amount for Del Mar      
 
       fDelMarSalesAmount = fPurchaseAmount + fDelMarSalesTax;            
       fEncinitasSalesAmount = fPurchaseAmount + fEncinitasSalesTax;  
       fLaJollaSalesAmount = fPurchaseAmount + fLaJollaSalesTax;
           
//      Display Sales Tax for Del Mar, Encinitas, La Jolla on the Purchase Amount
 
       printf("\n\n              Purchase Amount      Sales Tax     Total Sales Amount\n");
       printf("              _______________      _________     __________________\n\n");
       printf("\n   Del Mar         $%.2f            $%.2f            $%.2f\n",fPurchaseAmount, fDelMarSalesTax, fDelMarSalesAmount);
       printf("\n   Encinitas       $%.2f            $%.2f            $%.2f\n",fPurchaseAmount, fEncinitasSalesTax, fEncinitasSalesAmount);
       printf("\n   La Jolla        $%.2f            $%.2f            $%.2f\n",fPurchaseAmount, fLaJollaSalesTax, fLaJollaSalesAmount);  
     
//      Return zero to confirm that the program ran
       return 0;
}
ASKER CERTIFIED SOLUTION
masheik

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
masheik

hi nolte1964
the problem in your code is you are not coded the scanf correctly

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
nolte1964

ASKER
Thank you so very much, that was the solution to my problem.  I really appreciate the assistance.