minor bugs

for some reason this code will add up everything but it wont deduct the discount

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
   using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) 
{
	int e, s, c, f, total_discount, benefits;
	char med_choice, den_choice, vis_choice;
	enum benefits {medical,dental,vision};
	double benefits_total, discount;
	cout << "medical: ";
	cin >> med_choice;
	int med = 0;
	if (med_choice == 'e') {
		med = 0;
	}
	if (med_choice == 's') {
		med = 50;
	}
	if (med_choice == 'c') {
		med = 100;
	}
	if (med_choice == 'f') {
		med = 200;
	}
	med_choice = medical; 
	cout << "dental:";
	cin >> den_choice;
	int den = 0;
	if (den_choice == 'e') {
		den = 50;
	}
	else if (den_choice == 's') {
		den = 125;
	}
	else if (den_choice == 'c') {
		den = 225;
	}
	else if (den_choice == 'f') {
		den = 325;
	}
	den_choice = dental;
	cout << "vision: ";
	cin >> vis_choice;
	int vis = 0;
	if (vis_choice == 'e') {
		vis = 25;
	}
	else if (vis_choice == 's') {
		vis = 60;
	}
	else if (vis_choice == 'c') {
		vis = 110;
	}
	else if (vis_choice == 'f') {
		vis = 185;
	}
	vis_choice = vision;
	benefits = vis + den + med;
	cout << "years of service:";
	cin >> discount;
	if (discount >= 20) {
		discount=.20*(med_choice + den_choice + vis_choice);

	}
	else if (10 <= discount && discount <= 20) {
		discount=.10*(med_choice + den_choice + vis_choice);
	}
	else (discount <=10); {
		discount = 0;
	}
	discount = total_discount;
	benefits_total = (benefits * discount);
	cout << "total out of pocket premium" << benefits_total << "$"<<"\n";
	system("pause");
	return 0;
}
1
2
3
4
5
6
 In function 'int main(int, char**)':
7:6: warning: unused variable 'e' [-Wunused-variable]
7:9: warning: unused variable 's' [-Wunused-variable]
7:12: warning: unused variable 'c' [-Wunused-variable]
7:15: warning: unused variable 'f' [-Wunused-variable]
72:27: warning: 'total_discount' is used uninitialized in this function [-Wuninitialized]


Line 71 (in your post): You're assigning a junk value to discount, because total_discount is uninitialized. Seems to me that you probably just want to delete your line 71.

Also, you have discount being a double, but total_discount being an int. Not sure if that's intentional.

Also:
1
2
3
	else (discount <=10); {
		discount = 0;
	}

This not doing what you think it's doing. An else statement should not have a condition on it. It will always happen, as it's the last option.
1
2
3
	else {
		discount = 0;
	}


Last edited on
i fixed the errors you said and its still not doing what I'm trying to do

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vis_choice = vision;
	benefits = vis + den + med;
	cout << "years of service:";
	cin >> discount;
	if (discount >= 20) {
		discount=.20*(med_choice + den_choice + vis_choice);

	}
	else if (10 <= discount && discount <= 20) {
		discount=.10*(med_choice + den_choice + vis_choice);
	}
	else {
		discount = 0;
	}
	total = (benefits)-discount *(benefits);
	benefits_total=total;
	cout << "total out of pocket premium: " << benefits_total << "$"<<"\n";
	system("pause");
	return 0;

i want it to subtract the discount from those that have over ten years
I wasn't exhaustively listing all errors, but I was showing you the biggest ones I saw. Please stick to the other topic ( http://www.cplusplus.com/forum/beginner/231604/ ) if you have more questions, though.
Last edited on
Topic archived. No new replies allowed.