Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sales tax

Posted on 2003-03-29
5
Medium Priority
?
545 Views
Last Modified: 2010-04-15
I am not a programmer. I am looking to find the source code to calculate the
sales tax of number of items enter. Any help would be wonderful. The source code should be in C in Windows.

Input: # of items, price of each item, sales tax% of your state(will us 5%), amount tendered

Output: total and change returned if any

Thanks!
0
Comment
Question by:ladiet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
adg080898 earned 100 total points
ID: 8230408
I doubt anyone will sit down and write the whole program for you.

In any case, it is very simple to calculate (here is some pseudocode):

--------

subtot = 0
for each item {
    subtot += qty * unitprice
}

tax = subtot * taxrate
total = subtot + tax

change = amtpaid - total

--------

Where taxrate is 0.05 for 5% tax
0
 

Assisted Solution

by:bvbb
bvbb earned 100 total points
ID: 8230765
Here's a function that will do this. It assumes money amounts are stored as cents so they can be integers. If you're truly not a programmer, this won't be all you need, as it must be tied into the rest of your application.

int totalwithtax(int itemcount, int prices[], float rate, int tender, int totaltax, int change);
int totalwithtax(//calculate order total with sales tax
     int itemcount,     //number of items
     int prices[],          //array of item prices (in cents)
     float rate,               //tax rate as a fraction (for example, .0525 for 5.25%)
     int tender,               //amount tendered (in cents)
     int totaltax,          //used to return total sales tax to calling program (in cents)
     int change,               //used to return change owed to calling program (in cents)
     //function return value: total amount of order (in cents)
){
     int total=0;
     for ( i = 0; i < itemcount ; i++ ){
          total+=prices[i];
     }
     totaltax=int(total*rate+.5);
     total+=totaltax;
     change=tender-total;
     return total;
}
0
 
LVL 8

Expert Comment

by:adg080898
ID: 8233700
If you have Excel or other spreadsheet software then I would recommend that you use it to calculate your totals. It would be a lot less work than making a program from srcatch to do it.

In Excel you could record a few macros and assign them to buttons to clear the page and a field to enter amounts. Simple formulas would calculate the total, tax, and change.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10187251
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between adg and bvbb.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

722 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