need some help

i posted this on here early and someone helped me out with it but I'm still having trouble with it refuses to accept my inputs




char e, s, c, f;
enum benefits {medical,dental,vision};
bool med_choice, den_choice, vis_choice, discount, benefits;
double benefits_total;
cout << "medical: ";
cin >> med_choice;
int med = 0;
if (med_choice == e) {
med = 0;
}
else if (med_choice == s) {
med = 50;
}
else if (med_choice == c) {
med = 100;
}
else if (med_choice == f) {
med = 200;
}
med = medical;
cout << "end1";
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 = 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 = vision;
benefits = (vis + den + med);
cout << "years of service:";
cin >> discount;
if (discount >= 20) {
.20*(med + den + vis);

}
else if (discount <= 10 <= 20) {
.10*(med + den + vis);
}
benefits_total = benefits - discount;
cout << "total out of pocket premium" << benefits_total << "$"<<"/n";
system("pause");
return 0;

Put the code you need help with here.
[/code]
I would suggest you review guides on "fundamental types" in C++.
https://msdn.microsoft.com/en-us/library/cc953fe1.aspx

A bool can only be two values: true or false.

Which leads us into the second point, which is that a variable's name has no meaning for the actual logic of the program.
The fact that your char's variable name is e has nothing to do with the value inside that variable. It could be an 'e', or a 'g', or a '#'.

This is probably what you were actually going for:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Example program
#include <iostream>
#include <string>

int main()
{
    using namespace std;
    
    char med_choice;
    cout << "Enter med_choice: ";
    cin >> med_choice;
    if (med_choice == 'e')
    {
        cout << "You entered e!" << endl;   
    }
    else
    {
        cout << "You did not enter e." << endl;   
    }
}


See how the actual char value is 'e', with single quotation marks?

Also, when you post programs, it's extremely helpful if you actual post the whole program, or at least a simplified version of that can still compile without making us add the #includes and main function ourselves.

Also, put your code between [code] and [/code] tags to have it formatted correctly.

_________________________________

Furthermore, please note that the following lines don't do anything.
1
2
3
4
5
6
if (discount >= 20) {
    .20*(med + den + vis);
}
else if (discount <= 10 <= 20) {
    .10*(med + den + vis);
}

Nothing is happening here. Yes, the value 0.20*(med + den + vis) is being calculated, but the result of that calculation is not affecting the program in any way.

_________________________________

Further-furthermore:

 
else if (discount <= 10 <= 20)

if statements cannot work like this in C++, you have to give each condition as an individual statement:
 
else if (10 <= discount && discount <= 20)
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
	if (discount >= 20) {
		total_discount=.20*(med_choice + den_choice + vis_choice);

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

can you tell me why its still not working everything I'm the code works now but its still not adding the discount
Last edited on
heres the problem why isn't it adding up?


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
#include <iostream>
 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) 
{
	char med_choice, den_choice, vis_choice, discount ;
	enum benefits {medical,dental,vision};
	bool benefits;
	double benefits_total;
	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 = 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 = 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 = vision;
	benefits = (vis + den + med);
	cout << "total amount before the discount"<< benefits << "$" << "/n";
	cout << "years of service:";
	cin >> discount;
	if (discount >= 20) {
		.20*(med + den + vis);

	}
	else if (discount <= 10 <= 20) {
		.10*(med + den + vis);
	}
	benefits_total = benefits - discount;
	cout << "total out of pocket premium" << benefits_total <[code]
< "$"<<"/n";
system("pause");
return 0;
}[/code]
I don't know what you want it to do. But like I said earlier, look at your line 64 and 68. They don't do anything. They change nothing in the program. Also, your line 67 doesn't make sense, I believe you mean "if (10 <= discount && discount <= 20)"
I'm having serious trouble, can you tell me how to fix my mistake on line 62 and 65

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
 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);
	}
	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;
}
Okay, let's stick to one topic.

 
discount = total_discount;

Delete this. total_discount is never assigned a proper value. It's junk.

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

See my reply in the other thread to know why this is wrong.


1
2
3
4
5
6
	if (discount >= 20) {
		discount=.20*(med_choice + den_choice + vis_choice);
	}
	if (10 <= discount && discount <= 20) {
		discount=.10*(med_choice + den_choice + vis_choice);
	}


Change the second if to an else if.
med_choice, den_choice, and vis_choice are all chars. I don't think you should be using those there.
Perhaps you meant to use discount = 0.20 * benefits?
Also note that you have benefits as an int. The result will get truncated to the closest whole number.

_______________________

1
2
3
4
5
6
7
8
9
10
	if (discount >= 20) {
		discount=.20*(benefits);

	}
	else if (discount >= 10) {
		discount=.10*(benefits);
	}
	else {
	    discount = 0.0;
        }
Last edited on
thank you so much Ganado thanks to you i finally got to work how i needed
Glad to help. I also would delete your unused variables, to make the code cleaner.
need help, it's not working.


what is missing?

#include <iostream>
using namespace std;


int main(int argc, char** argv)
{
int 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*(benefits);

}
else if (discount >= 10) {
discount=.10*(benefits);
}
else {
discount = 0.0;
}

benefits_total = (benefits * discount);
cout << "total out of pocket premium" << benefits_total << "$"<<"\n";
system("pause");
return 0;
}
For example:
Enter your selections
Medical: f
Dental: c
Vision: e
Years of service: 15
Total out-of-pocket premium: 405.00

it shows the result as 20250

and i want it to be 405.00
Perhaps you meant to do benefits_total = benefits - discount;, not (benefits * discount);
Thank you so much Ganado
Topic archived. No new replies allowed.