How to declared tax as a constant ?

Hi Im a beginner(obviously)currently writting a program for my assigment on Dev++ (version 5.11), the assignment question stated that "Your C++ Program Must Declare tax rate as Constant"

I've try to declared it as

const tax=(3/100);

but it still prompted an error that says "tax does not name a type"
have tried to find solutions multiple forum post, but couldn't find anything.
i've tried to changed it to

const double tax=(3/100);
but this one does nothing because the end product still doesn't count the total amount of tax

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
//Program to generate a customer's bill for company
#include<iostream>
using namespace std;

int main()
{
	double cds,keyboards,printers,pendrives,speakers;
	cout<<"====================== Bill Generator ======================== \n"<<endl;
	 cout<<" Enter The Amounts of CDs (per pack): "; //enter the amount of the items
	   cin>>cds;                                     //program will receive inputs from tthe user 
	 cout<<" Enter The Amounts of Keyboards: ";
	   cin>>keyboards;
	cout<<" Enter The Amounts of Printers: ";
	  cin>>printers;
	cout<<" Enter The Amounts of Pendrives: ";
	  cin>>pendrives;
	cout<<" Enter The Amounts of Speakers: ";
	  cin>>speakers;
	  
    double unit_price_cd=60.00;//unit price is price for one item
    double unit_price_keyboard=130.00;
    double unit_price_printer=550.00;
    double unit_price_pendrive=50.00;
    double unit_price_speaker=150.00;
    
    const tax=(3/100);//tax equals 3% of the sub total
    
    double total_price_cd=cds*unit_price_cd;//total price for item based on the quantity given 
    double total_price_keyboard=keyboards*unit_price_keyboard;
    double total_price_printer=printers*unit_price_printer;
    double total_price_pendrive=pendrives*unit_price_pendrive;
    double total_price_speaker=speakers*unit_price_speaker;
    
    double sub_total=total_price_cd+total_price_keyboard+total_price_printer+total_price_pendrive+total_price_speaker;//sub total is price for all items
    double tax_amount=tax*sub_total;//total amount of tax 
    double total=sub_total+tax_amount;//total for all item plus tax 
    
    cout<<"                                                              "<<endl;
    cout<<"============================================================== \n"<<endl;
	cout<<"QTY      DETAILS     UNIT PRICE                 TOTAL PRICE"<<endl;
	cout<<"____     _______     __________                 ___________"<<endl;
	cout<<"                                                              "<<endl;
	cout<<cds<<"        CD           60.00                  "<<"\t  "<<total_price_cd<<".00"<<endl;
	cout<<keyboards<<"      KEYBOARD    130.00                "<<"\t"<<total_price_keyboard<<".00"<<endl;
	cout<<printers<<"       PRINTER     550.00                "<<"\t"<<total_price_printer<<".00"<<endl;
	cout<<pendrives<<"      PENDRIVE     50.00                 "<<"\t"<<total_price_pendrive<<".00"<<endl;
	cout<<speakers<<"       SPEAKER     150.00                "<<"\t"<<total_price_speaker<<".00"<<endl;
	cout<<"                                                ___________"<<endl;
	cout<<"                                    SUB TOTAL   "<<sub_total<<".00"<<endl;
	cout<<"                                    TAX             "<<tax_amount<<".00"<<endl;
	cout<<"                                    TOTAL       "<<total<<".00"<<endl;
	return 0;
 } 
3/100 is an integer division. I.e. it returns 0. Change it to e.g.:

const double tax=(3.0/100); // Note: Due to .0 it is not an integer division anymore
coder 777 it worked, thanks i appreciate your help
Topic archived. No new replies allowed.