Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
5. Calculate the tax on net income of a person. Rules for calculating tax are
• No tax is paid on first Rs. 15,000 of net income.
• A tax of 5% is assessed on each rupee of net income over Rs. 15,001 to Rs. 25,000.
• A tax of 10% is assessed on each rupee of net income over Rs. 25,000

C++
#include<iostream>
using namespace std;
void main()
{
	int tax, income;
	cout << "please enter your income" << endl;
		if
			(income <= 15000)
			cout << "No Tax on you ! keep enjoying";
		else if
			(income <= 25000)
			tax = (income - 15000)*0.05;
		cout << "Tax=" << tax << endl;
		else
			(income > 25000)
			tax = (1000 * 0.05) + ((income-25000)*0.1);
		cout << "Tax=" << endl;
	system("pause"); 
}
</iostream>

I try but it gives error on visual studio
Posted
Updated 4-Oct-15 12:01pm
v2
Comments
CHill60 4-Oct-15 17:09pm    
What have you tried? Where are you stuck?
Member 12032240 4-Oct-15 17:58pm    
#include<iostream>
using namespace std;
void main()
{
int tax, income;
cout << "please enter your income" << endl;
if
(income <= 15000)
cout << "No Tax on you ! keep enjoying";
else if
(income <= 25000)
tax = (income - 15000)*0.05;
cout << "Tax=" << tax << endl;
else
(income > 25000)
tax = (1000 * 0.05) + ((income-25000)*0.1);
cout << "Tax=" << endl;
system("pause");
}
nv3 4-Oct-15 17:47pm    
Tell your teacher that taxes are not calculated on net income, but on gross income :-) As for the programming task at hand: Just look into your course notes. If you can't do this simple assignment, I would advise to better find another career.
Mohibur Rashid 4-Oct-15 22:23pm    
agreed
Member 12032240 4-Oct-15 17:57pm    
my classes start just 2 weaks ago so please keep your advice to your own !

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
(Used with permission of OriginalGriff)


First mistake: Your program ask to type the income but never read the keyboard.
second mistake: there is no condition after else, only after if.
You should also read about the usage of {} with if statement.
 
Share this answer
 
v4
Comments
Member 12032240 4-Oct-15 17:56pm    
#include<iostream>
using namespace std;
void main()
{
int tax, income;
cout << "please enter your income" << endl;
if
(income <= 15000)
cout << "No Tax on you ! keep enjoying";
else if
(income <= 25000)
tax = (income - 15000)*0.05;
cout << "Tax=" << tax << endl;
else
(income > 25000)
tax = (1000 * 0.05) + ((income-25000)*0.1);
cout << "Tax=" << endl;
system("pause");
}
i try but it gives error on visual studio
Patrice T 4-Oct-15 18:02pm    
I have Improved your question

Now tell us what is the error you get and where.
Member 12032240 4-Oct-15 18:06pm    
it says illegle else without if
Member 12032240 4-Oct-15 18:07pm    
please can you tell me where am wrong in this !
Member 12032240 4-Oct-15 18:17pm    
i use else if then else and in else there is no condition can you tell how i solve problem illegle else without if this error shows again and again
you are not using { and } that will give you error: illegal else without if

C++
#include<iostream>
using namespace std;
void main()
{
	    int  income;
        float tax;          // make float variable, value may be in decimal points
	    cout << "please enter your income" << endl;
		if(income <= 15000)
        {                               //open {
		    cout << "No Tax on you ! keep enjoying";
        }                               //Close }
		else if(income <= 25000)
        {                               //open {
		    tax = (income - 15000)*0.05;
		    cout << "Tax=" << tax << endl;
        }                               //Close }
		else if(income > 25000) // or you can keep only 'else' without any condition
        {                               //open {
		    tax = (10000 * 0.05) + ((income-25000)*0.1);
		    cout << "Tax=" << endl;
        }                               //Close }
	system("pause"); 
}
</iostream>
 
Share this answer
 
v3
Comments
Philippe Mori 5-Oct-15 12:31pm    
Well, you have some points but last else is still incorrect. if you have a condition, then you need an if for that condition. In this case last condition is not needed.
Member 10641779 7-Oct-15 5:25am    
Sry, actually I just copied the code and make changes on that. it should have to be else if(conditon) or only else.
phil.o 7-Oct-15 5:33am    
Copying code while learning is the worst idea you could have had.
If you want to learn, then really do it, and begin to write your code yourself.
Copying code from anywhere and expecting someone else to customize it to your own need is not a developper's behavior.
Richard MacCutchan 7-Oct-15 6:16am    
Don't use floting point in financial calculations, you will end up charging the wrong amounts of tax. See http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html.
Stefan_Lang 12-Oct-15 2:55am    
No worries, this sure isn't going to be used in a live system. Live systems would be more like this:
"How much have you earned last year?"
"Send it to us!"
;-P

Just joking - on a more serious note: good advice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900