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 pointint 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;}
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
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