Help with Code

i have to write a code to figure out medical the price of out of pocket premiunms and I'm having some issues with it if you could help me i would really appricate it heres the question and the code is under it
• Medical
• Employee-only: $0
• Employee+spouse: $50
• Employee+child(ren): $100
• Employee+family: $200
• Dental
• Employee-only: $50
• Employee+spouse: $125
• Employee+child(ren): $225
• Employee+family: $325
• Vision
• Employee-only: $25
• Employee+spouse: $60
• Employee+child(ren): $110
• Employee+family: $185

Premium discount
• If employee has 20+ years of service, they get 20% discount from the total premium.
• If 10 - 20 years of service, 10% discount

Inputs from user
• Benefits selections: Medical, Dental, Vision
• Use Employee-only: e
• Employee+spouse: s
• Employee+child(ren): c
• Employee+family: f
• Years of service

For example:
Enter your selections
Medical: f
Dental: c
Vision: e
Years of service: 15
Total out-of-pocket premium: 405.00

Here is the calculation…
(200+225+25)-10%(200+225+25) = 450-45 = 405

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
enum benefits {medical, dental, vision};
int e, s, c, f, benefits, benefits_2, benefits_3, discount;
string outputs, e,s ,c,f;
cout << "medical: ";
cin >> benefits;
if (benefits == e) {
e = 0;
}
else if (benefits == s) {
s = 50;
}
else if (benefits == c) {
c = 100;
}
else if (benefits == f) {
f = 200;
}
cout << "dental:";
cin >> benefits_2;
if (benefits_2 == e) {
e = 50;
}
else if (benefits_2 == s) {
s = 125;
}
else if (benefits_2 == c) {
c = 225;
}
else if (benefits_2 == f) {
f = 325;
}
cout << "vision: ";
cin >> benefits_3;
if (benefits_3 == e) {
e = 25;
}
else if (benefits_3 == s) {
s = 60;
}
else if (benefits_3 == c) {
c = 110;
}
else if (benefits_3 == f) {
f = 185;
}
cout << "years of service:";
cin >> discount;
if (discount >= 20) {
(benefits + benefits_2 + benefits_3) - 20

}
system("pause");
return 0;
}
I think you are on the right track but confusing yourself.

made up incorrect values but to get the point across:
if(benefits == s)
benefitsprice = 50;
else if (benefits == c)
benefitsprice = 250; //where benefits price would be 3 variables, one for medical, one for dental, one for vision, and working the problem in those 3 sections as best you can.
..

the idea being that each group populates 1 price
then total all the prices at the end.

this would be a lot easier if you had vectors, and could make a boolean for each possible product, set it for each one owned, and then did a quick sum of (is_owned*thatproductsprice) and at the end took the discount % multiply to finish up, which would be done in a vector, but you may not have those tools available yet.

Try to reduce the number of variables and conditions as best you can so you can organize and manage the code.

discount is a multiply, not a subtraction. So if they get a 20% discount, you multiply by 0.8 and the result is a floating point value not an integer. % is NOT a percent operation. It is the remainder from long division (in case you were tempted).

something like 3 sections of
int med = 0;
if(med_choice == s)
med = 50;
if(med_choice == c)
med = 100;
if(med_choice == f)
med = 200;

...
followed by adding it up and finding the discount
double total = 0.0;
double discount = 1.0;
...
total = (med+dental+vis)*discount;

Last edited on
thank you how does it look now

int e, s, c, f;
bool med_choice, den_choice, vis_choice, discount, med, den, vis;
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;
}
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;
}
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;
}
cout << "years of service:";
cin >> discount;
if (discount >= 20) {
.20*(med + den + vis);

}
else if (discount <= 10 <= 20) {
.10*(med + den + vis);
}
benefits_total = (med + den + vis) - discount;
system("pause");
return 0;
I'm sorry this code



int e, s, c, f;
bool med_choice, den_choice, vis_choice, discount, med, den, vis;
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;
}
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;
}
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;
}
cout << "years of service:";
cin >> discount;
if (discount >= 20) {
.20*(med + den + vis);

}
else if (discount <= 10 <= 20) {
.10*(med + den + vis);
}
benefits_total = (med + den + vis) - discount;
cout << "total oout of pocket premium" << benefits_total << "/n";
Topic archived. No new replies allowed.