Sales Tax

Tax
Creative Commons License photo credit: Phillip

This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (2) was titled “Introduction to C++”.

2.3: Write a program that will compute the total sales tax on a $52 purchase. Assume the state sales tax is 4 percent and the county sales tax is 2 percent.

My solution (using hard-coded values as per instructions):

/* Chapter 2 Challenge 3
Written by Kirk Hingsberger
Sept 12, 2007
Sales tax problem
*/

#include
using namespace std;

int main()
{
float purchase = 52;
float taxState = .04;
float taxCounty = .02;
float totalTax = (taxState + taxCounty ) * purchase;

cout << "Total sales tax (including state and county taxes) on a ";
cout << "$" << purchase << " purchase will be $" << totalTax << "." << endl;

return 0;
}

Here is the capture script I turned in for grading:

Script started on Thu 13 Sep 2007 10:10:14 AM MDT
$ cat chap2chlg3.cc
/* Chapter 2 Challenge 3
Written by Kirk Hingsberger
Sept 12, 2007
Sales tax problem
*/

#include
using namespace std;

int main()
{
float purchase = 52;
float taxState = .04;
float taxCounty = .02;
float totalTax = (taxState + taxCounty ) * purchase;

cout << “Total sales tax (including state and county taxes) on a “;
cout << “$” << purchase << ” purchase will be $” << totalTax << “.” << endl;

return 0;
}
$ g++ -o chap2chlg3 chap2chlg3.cc -s
$ chap2chglg3
Total sales tax (including state and county taxes) on a $52 purchase will be $3.12.
$ exit
exit

Script done on Thu 13 Sep 2007 10:10:47 AM MDT

Share




Leave a Reply