Calculate tax

hi guys this is my first post on cplusplus

here is my problem ..
when i run it. it doesn't calculate the tax.
if someone help with this that would be great.
thanks a lot.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include <iostream>
  #include <iomanip>

using namespace std;


const double stateSalesTaxRate = 0.04;
const double countyTaxRate = 0.02;




int main()
{

    double PURCHASE_PRICE;
    double STATE_SALES_TAX_AMOUNT;
    double COUNTY_SALES_TAX_AMOUNT;
    double TOTAL_SALES_TAX_AMOUNT;
    double stateSalesTaxRate = 0.04;
    double countyTaxRate = 0.02;
    
    
   
    
    
    
    cout << "Enter The Purchase Price\n";
    cin >> PURCHASE_PRICE;
    
    cout << "State Tax Amount is \n";
    cin >> STATE_SALES_TAX_AMOUNT;
    cout << endl;
    
     STATE_SALES_TAX_AMOUNT = PURCHASE_PRICE * stateSalesTaxRate;
    
    cout << "County Tax Amount is \n";
    cin >> COUNTY_SALES_TAX_AMOUNT;
    cout << endl;
    
    COUNTY_SALES_TAX_AMOUNT = PURCHASE_PRICE * countyTaxRate;
    
    cout << "Total Tax Amount is \n";
    cin >> TOTAL_SALES_TAX_AMOUNT;
    cout << endl;
    
    TOTAL_SALES_TAX_AMOUNT = PURCHASE_PRICE * (stateSalesTaxRate + countyTaxRate);
    
    
    
    
    return 0;
}
closed account (48T7M4Gy)
I haven't checked your calculation but what you need is a final line (48) with a
cout << "Total tax: " << TOTAL_SALES_TAX_AMOUNT << endl; statement

Also,
What is the reason for lines 43, 44 and 45 when you calculate the total tax at line 47?

Last edited on
The problem is you printed the value before calculating it.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    double PURCHASE_PRICE;
    double STATE_SALES_TAX_AMOUNT;
    double COUNTY_SALES_TAX_AMOUNT;
    double TOTAL_SALES_TAX_AMOUNT;
    double stateSalesTaxRate = 0.04;
    double countyTaxRate = 0.02;
    
    cout << "Enter The Purchase Price: $";
    cin >> PURCHASE_PRICE;
    
    STATE_SALES_TAX_AMOUNT = PURCHASE_PRICE * stateSalesTaxRate;
    cout << "      State Sales Tax Amount is: $" << STATE_SALES_TAX_AMOUNT << endl;
    
    COUNTY_SALES_TAX_AMOUNT = PURCHASE_PRICE * countyTaxRate;
    cout << "     County Sales Tax Amount is: $" << COUNTY_SALES_TAX_AMOUNT << endl;
    
    TOTAL_SALES_TAX_AMOUNT = STATE_SALES_TAX_AMOUNT + COUNTY_SALES_TAX_AMOUNT;
    
    cout << "                      Total tax: $" << TOTAL_SALES_TAX_AMOUNT << endl;
    
    return 0;
}


Enter The Purchase Price: $900
      State Sales Tax Amount is: $36
     County Sales Tax Amount is: $18
                      Total tax: $54
 
Last edited on
closed account (48T7M4Gy)
The problem is you printed the value before calculating it.


That's not quite right. There are no cout statements in the OP before or after relevant to the last calculation.
here is the question that i was trying to solve :
A program that inputs the purchase price, then calculates the state sales tax amount, county sales tax amount, and total sales tax amount on the purchase. Assume the state sales tax rate is 4 percent and the county tax rate is 2 percent. Display the purchase price, state tax amount, county tax amount, and total tax amount on the screen.

i know i missed something but i couldn't make it .
closed account (48T7M4Gy)
i know i missed something but i couldn't make it .


I'm not sure what you mean but if you have a look at what I did u might be able to make some use of it. You don't really need to display the purchase price because it already appears in answer to the first prompt. If you want to explicitly print it out just add another cot << etc statement. :)
Last edited on
alright thanks a lot.
Line 19 says it displays the county tax but actually displays the state sales tax.

Line 22 says it displays the total tax but actually displays the county tax.
closed account (48T7M4Gy)
It doesn't any more. Well spotted.
Topic archived. No new replies allowed.