Making program a function

Hi guys, the professor wants us to put all the programs we did into functions in 1 program and prompt the user to select which one he wants to run. I have about 8 programs to fit but if you can help me out with just one (as I displayed in my code) I should be able to take care of the rest. The function and the header are in the code as IncTax, I know how to do a function if Im getting the input in the main and using it in the function, but I dont know how to address a function to ask for the input and process the entire thing. Thanks in advance fellas.

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
#include<iostream>
#include<iomanip>
#include<string>
#include<cctype>
#include<cmath>
#include<stdlib.h>
using namespace std;

//Function prototypes
void IncTax();

int main()
{
	int selection;
	while(cin)
	{
	cout<<"1)Income Tax Calculator"<<endl<<"2) EXIT\n";
	cin>>selection;
	if(selection==1)
		IncTax;
	if(selection==2)
		break;
	system("cls");
	}
	return 0;
}	

void IncTax()
{
	string corp;
	double slry,tx;
	cout<<setprecision(2)<<fixed;

	cout<<"Enter Company Name:\n";
	cin>>corp;
	cout<<"***************************************************\n\n\n\n";
	cout<<"\t\t\t"<<corp<<"\n\n\n\n";
	cout<<"***************************************************\n\n\n\n";
	cout<<"Enter Your Annual Salary-->  ";
	cin>> slry;
	if(slry<15000)
		tx=0.15*slry;
	else if(slry>=15000 && slry<30000)
		tx=2250+0.16*(slry-15000);
	else if(slry>=30000 && slry<50000)
		tx=4650+0.18*(slry-30000);
	else if(slry>=50000 && slry <80000)
		tx=8250+0.20*(slry-50000);
	else
		tx=14250+0.25*(slry-80000);
	cout<<"\n\n";
	cout<<"Your Tax Due Is: $"<<tx;
	cout<<"\n\n\n\n";
	cout<<"***************************************************\n\n\n\n";

	system("PAUSE");
}
Last edited on
Hi,
I got it working with only one change

1
2
3
4
5
6
    if (selection==1)
        IncTax;

       //changed to
    if (selection==1)
        IncTax();


You have got the right idea about how to do it.

good luck
Shredded
Thanx a bunch shredded that takes care of my last project for this course.
Topic archived. No new replies allowed.