Sales Tax help

How can i fix my sales tax calculator

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
  #include <iostream>
using namespace std;

int main() {
	double taxRate;
	double itemPurchase;
	double theTotal;
	double theTax;
	//get the tax of the item
	cout << "Current state taxrate: " << endl;
	cin >> taxRate;
	//get the amount of the item going to be purchased
	cout << "How much is your item without taxes: " << endl;
	cin >> itemPurchase;
	//get the tax and then add to get total
	cout << "The tax for this item will be: " << itemPurchase*taxRate / 100.00 << endl;
	cin >> theTax;
	//additions to get the total
	cout << "Calculating.... " << theTax + itemPurchase;
	cin >> theTotal;
	//the total
	cout << "Your total is: " << theTotal << endl;


	return 0;

	
}
Last edited on
How can i fix my sales tax calculator

What's wrong with it?

Line 17: Shouldn't you be calculating theTax instead of asking the user for it?

Line 20: Shouldn't you be calculating theTotal instead of asking the user for it?
Last edited on
what about this one?
This one when its about to say the total is it just closes.
This ONE seems to work fine also but it closes after it tells me the total.
What i want to create is like a receipt program.
which will say Item: 300
which will say Taxes: 24.75
________
which will say Total: 324.75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main() {
	double taxRate;
	double itemPurchase;
	double theTotal, theTax;

// calculation for taxes
	cout << "Current state taxrate: ";
	cin >> taxRate;
	cout << "Item worth $: ";
	cin >> itemPurchase;
	theTax = itemPurchase*taxRate / 100.0;
	theTotal = theTax + itemPurchase;
	cout << "Your total is: " << theTotal;

	return 0;

	
}
Last edited on
You should initialise your variables.

1
2
3
double taxRate = 0.0;
double itemPurchase = 0.0;
double theTotal = 0.0, theTax = 0.0;


You can use cin.get () or system ("PAUSE); to stop the program closing immediately
1
2
cin.get ();
return 0;


Or

1
2
system("PAUSE");
return 0;


But system ("PAUSE"); is only supposed to be used in small programs like this, since its slow
Last edited on
Topic archived. No new replies allowed.