The Tax lesson

To try and accomplish this lesson i had to learn a little bit about how to figure up the mathematical end of it all. The code isn't really all that difficult once the formula is figured out.
This lesson is all about using If Else statements in such a way as figuring out how much and item costs before tax and how much tax has then been placed upon that item.
For Example; I have to pay $123 for an item at the cash register, and I know that the tax in my area is 23%. That would make the item original price tag $100 and the tax on the item $23 finishing out with a final price of $123.00.
That example is really simple. because it is based off of perfect numbers... But what about the following scenario?
The final price being $123 and the tax rate being 50%........
These numbers changed EVERYTHING!!! I struggled with this and struggled with this until I finally found this Web page...
Click on the picture above to go to the web page
On this web page I found a formula that I never knew before. It is actually really simple and straight forward.
Here is how it breaks down.
Take the percent... In the example it is 50% and divide it by 100... giving us .50, then add 1 to it. This will give us the number 1.5
We then take the Gross price of $123 and divide it by 1.5, that we got from the previous step. This gives us $82, which is the original price of the item that we call the Net price. If we take $82 and subtract it from $123 that would give us $41 which is half of $82 and so that confirms everything.
In my video below I will basically do this same procedure as I just described above, for those that don't get it from the text.
This lesson is all about using If Else statements in such a way as figuring out how much and item costs before tax and how much tax has then been placed upon that item.
For Example; I have to pay $123 for an item at the cash register, and I know that the tax in my area is 23%. That would make the item original price tag $100 and the tax on the item $23 finishing out with a final price of $123.00.
That example is really simple. because it is based off of perfect numbers... But what about the following scenario?
The final price being $123 and the tax rate being 50%........
These numbers changed EVERYTHING!!! I struggled with this and struggled with this until I finally found this Web page...
Click on the picture above to go to the web page
On this web page I found a formula that I never knew before. It is actually really simple and straight forward.
Here is how it breaks down.
Take the percent... In the example it is 50% and divide it by 100... giving us .50, then add 1 to it. This will give us the number 1.5
We then take the Gross price of $123 and divide it by 1.5, that we got from the previous step. This gives us $82, which is the original price of the item that we call the Net price. If we take $82 and subtract it from $123 that would give us $41 which is half of $82 and so that confirms everything.
In my video below I will basically do this same procedure as I just described above, for those that don't get it from the text.
The Assignment
Wherever you are and whatever you pay for, you usually spend your money on two things:
the first is for a good or service you are buying, and the second is taxes.
This means that the amount of money you are transferring (named "gross price") to the seller is a sum of the actual price (named "net price") and the tax.
The tax is calculated as a percentage of the net price and its rate depends on a lot of unpredictable factors (e.g. where you live, what you buy, etc., etc., etc.).
Your task is to write a simple "tax calculator" – it should accept two values:a gross price and a tax rate expressed as a percentage (i.e. a value greater than 0 and, let's be optimistic, less than 100).
Look at the code below – it only reads two input values and outputs the results, so you need to complete it with a few smart calculations. It would be good to verify if the values entered are reasonable (e.g. gross price is greater than zero and tax rate falls into the previously mentioned range).
Test your code using the data we've provided.
the first is for a good or service you are buying, and the second is taxes.
This means that the amount of money you are transferring (named "gross price") to the seller is a sum of the actual price (named "net price") and the tax.
The tax is calculated as a percentage of the net price and its rate depends on a lot of unpredictable factors (e.g. where you live, what you buy, etc., etc., etc.).
Your task is to write a simple "tax calculator" – it should accept two values:a gross price and a tax rate expressed as a percentage (i.e. a value greater than 0 and, let's be optimistic, less than 100).
Look at the code below – it only reads two input values and outputs the results, so you need to complete it with a few smart calculations. It would be good to verify if the values entered are reasonable (e.g. gross price is greater than zero and tax rate falls into the previously mentioned range).
Test your code using the data we've provided.
Sample Code
#include
using namespace std;
int main(void)
{
float grossprice, taxrate, netprice, taxvalue;
cout << "Enter a gross price: ";
cin >> grossprice;
cout << "Enter a tax rate: ";
cin >> taxrate;
// Insert you code here
cout << "Net price: " << netprice << endl;
cout << "Tax value: " << taxvalue << endl;
return 0;
}
using namespace std;
int main(void)
{
float grossprice, taxrate, netprice, taxvalue;
cout << "Enter a gross price: ";
cin >> grossprice;
cout << "Enter a tax rate: ";
cin >> taxrate;
// Insert you code here
cout << "Net price: " << netprice << endl;
cout << "Tax value: " << taxvalue << endl;
return 0;
}