Help with functions

I'm supposed to get hours, and a letter, then work it out.

So,
-I get integer "h" with int getHrs
-I get char "p" with int getPkg
-I set ranges for h and p with getValidHrs, and getValidPkg
-I don't know what to do after that.

I'm supposed to get the Bill from an internet service company based on what package they have and the amount of hours they watched.

I don't know what I'm doing. I'm supposed to display it on a different .cpp file by using a header file to connect both .cpp files.

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 // My functions

#include <string>
#include <iostream>
using namespace std;

int getHrs(string prompt) // Get Hours
{
	int n(0);

	cout<< prompt << ": ";
	cin >> n;

	return n;
}

int getPkg(string prompt) // Get Package
{
	char w;
	
	cout<< prompt << ": ";
	cin>> w;

	return w;
}

int getValidHrs(string prompt) // get valid hours
{
	int h(0);

	h=getHrs(prompt);

	if (h>=0 && h<= 720)
		{
			cout<< "We provided you with " <<h<< " hours." << endl<<endl;
		}
		else
		{
			cout<< "Invalid Number of Hours" <<endl<<endl;
		}

	return h;
}

int getValidPkg(string prompt) //Get valid package
{
	char p;

	p=getPkg(prompt);
	p = toupper(p);

	if(p >= 'A' && p<='C')
		{
			cout<< "You have package "<<p<< "."<< endl<<endl;
		}
		else
		{
			cout<< "Package Does Not Exist \n"<< endl;
		}

	return p;
}

double calcA(char p, int h) //calc if A
{
	double t(0);

	int base_A = 15;

	if (h <= 50)
		t = base_A;
	else
		t = (2 * (h - 50)) + base_A;
	
	return t;
}

double calcB(int h, char p) //calc if B
{
	double t(0);
	int base_B = 20;

	if (h <= 100)
		t = base_B;
	else
		t = (1.5 * (h - 100)) + base_B;
	
	return t;
}

double calcC(int h, char p) //calc if C
{
	double t(0);
	int base_C = 25;

	if (h <= 150)
		t = base_C;
	else
		t = (1 * (h - 150)) + base_C;

	return t;
}

double calcChgs(int t, char p)
{
	double c(0);

	switch(p)
	{
	case 'A':
		c = calcA(p, t);
		break;
	case 'B':
		c = calcB(p, t);
		break;
	case 'C':
		c = calcC(p, t);
		break;
	}
	
	return c;
}

double showBill(int c, char p)
{
	double u(0);

	u = calcChgs(p, c);

	return u;
}


closed account (48T7M4Gy)
So where's the rest of it? Perhaps the file with "int main()" that you forgot to mention?
Here it is, but I don't know how to connect both files.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "_MyDeclarations.h"

#include <iostream>
using namespace std;

void main()
{
	int hrs = getValidHrs("How many hours did we provide you with?");

	char pkg = getValidPkg("What package do you have with us?");
	
	
}
closed account (48T7M4Gy)
OK so where is the file "_MyDeclarations.h"? Usually when you #include files there are two riles, the .h file and the .cpp file which are the header or interface file and the .cpp is the implementation file. Yours (so far) looks like an implementation file and you #include won't 'see' it because it's calling up header file.

So what you need to do is get the header file. Since you wrote it, it won't be hard to find.

Or change the #include or change the name of the file you do have. :)
Topic archived. No new replies allowed.