Help me with my code?

1) const double taxrate = 0.0875;
According to checkpoint 3 this must be "Use a defined constant for the tax rate"

2) Price for each item according to checkpoint 4 must be "Use a memory constant for each unit price

3) The decimal points do not line up (see checkpoint 5). The issue is that the words like
"DVD"
must be left justified and not right.

For number one, she wants me to use a defined constant for the tax rate but when I did, it won't let me input it to create the tax. It gives me a red line in
"tax = subtotal * taxrate;" Anyone help? thanks in advgance

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
55
56
57
58
59
60
61
 #include <iostream>
#include <iomanip>
#include <string>
using namespace std;




int main()
{
	//Declaring The Quantity
	int tvquan, dvdquan, remotequan, cdplaquan,
		avquan;

	//Declaring The Prices of Each Items
	const double tvprice = 500.00, 
		dvdprice = 380.00, 
		remoteprice = 35.20, 
		cdplaprice = 75.50,
		avprice = 1500.00;                  
#define const taxrate = 0.0875;

	//Declaring The Total Amount (This is where the input of quantity * the prices goes)
	double tvtotal, dvdtotal, remotetotal, cdtotal,
		avtotal, subtotal, tax, total;

	//Inputing
	cout << "How many TVs were sold? ";
	cin >> tvquan;
	cout << "How many DVD players were sold? ";
	cin >> dvdquan;
	cout << "How many Remote Controllers units were sold? ";
	cin >> remotequan;
	cout << "How many CD Players were sold? ";
	cin >> cdplaquan;
	cout << "How many AV Processors were sold? ";
	cin >> avquan;
	

	//This computes the tax, total of each quantity that was input, and the total of all items together combined
	tvtotal = tvquan * tvprice;
	dvdtotal = dvdquan * dvdprice;
	remotetotal = remotequan * remoteprice;
	cdtotal = cdplaquan * cdplaprice;
	avtotal = avquan * avprice;
	subtotal = tvtotal + dvdtotal + remotetotal + cdtotal + avtotal;
	tax = subtotal * taxrate;
	total = tax + subtotal;


	//Output The Total of all Items That were Input in the Variables
	cout << setprecision(2) << fixed; // 
	cout << "\n\nQTY            " << "Description" << "           Unit Price          " << "Total Price" << endl;
	cout << right << setw(2) << tvquan << right << setw(15) << "TV" << right << setw(20) << "$" << tvprice << right << setw(15) << "$" << tvtotal << endl;
	cout << right << setw(2) << dvdquan << right << setw(16) << "DVD" << right << setw(19) << "$" << dvdprice << right << setw(15) << "$" << dvdtotal << endl;
	cout << right << setw(2) << remotequan << right << setw(30) << "REMOTE CONTROLLER" << right << setw(5) << "$" << remoteprice << right << setw(16) << "$" << remotetotal << endl;
	cout << right << setw(2) << cdplaquan << right << setw(22) << "CD PLAYER" << right << setw(13) << "$" << cdplaprice << right << setw(16) << "$" << cdtotal << endl;
	cout << right << setw(2) << avquan << right << setw(25) << "AV PROCESSOR" << right << setw(10) << "$" << avprice << right << setw(14) << "$" << avtotal << endl << endl;
	cout << right << setw(44) << "Subtotal: $" << subtotal << endl;
	cout << right << setw(44) << "Tax: $" << tax << endl;
	cout << right << setw(44) << "Total: $" << total << endl << endl;
#define const taxrate = 0.0875;

I won't comment on the use of #define for this, but there is still something missing.
<hint>
A four letter word that starts with a t
</hint>
how did you define the taxrate previously?

#define works like search and replace.

eg; #define myAge 21 will replace all occurences of "myAge" with "21" in the source code before the compiler sees it.

when your tutor said use a "defined const" it could mean one of two things, either what i said above, or what you did to define the other consts in your code.

Topic archived. No new replies allowed.