/*
2-70 Complex Retirement
This is an "extra credit" assignment, more difficult than most. This assignment is one of the hardest ways to get a point in the course.
Improve your Retirement program based on these rules. Eligibility for retirement is based on age (how old the worker is) and service (how long the worker has worked at the company).
1. 30 and out: anyone with 30 years service can retire, no matter how old.
2. You can retire if you are 65 years old, no matter how may years of service.
3. You can retire at age 60 with 20 years experience.
4. You can retire at age 55 with 25 years experience.
The program should ask for the necessary information, then tell the person whether or not they can retire.
Then, the program will tell how long until retirement for those who are not immediately eligible.
For example,
a person 21 years old with 1 year experience can retire in 29 years (under rule 1); a person 31 years old with 1 year
experience can retire in 24 years (under rule 4); a 41 year old with 1 year can retire in 19 years (under rule 3);
a 51 year old with 1 year can retire in 14 years (under rule 2).
*/
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
double Age;
double Service;
double Rule1;
double Rule2;
double Rule3;
double Rule35;
double Rule4;
string one = Service <= 30;
string two = Age <= 65;
string three = Age <= 60 && Service <= 20;
string four = Age <= 55 && Service <= 25;
cout << "Welcome to the retirement program decider! I will tell you whether or not you can retire if you tell me your age and service.\n";
cout << "Rule 1 is: 30 and out: anyone with 30 years service can retire, no matter how old.\n";
cout << "Rule 2 is: You can retire if you are 65 years old, no matter how may years of service.\n";
cout << "Rule 3 is: You can retire at age 60 with 20 years experience. \n";
cout << "Rule 4 is: You can retire at age 55 with 25 years experience.\n";
cout << "What is your age? ";
cin >> Age;
cout << "How many years have you worked for?";
cin >> Service;
if ( Service >= 30 || Age >= 65 || Age >= 60 && Service >= 20 || Age >= 55 && Service >= 25 )
{cout << "You can retire!\n";}
else
{cout << "You cannot retire.\n";}
if ( one )
Rule1 = 30 - Service;
{cout << "You can retire in "
<< Rule1
<< "years.\n";}
elseif ( two )
Rule2 = 65 - Age;
{cout << {cout << "You can retire in "
<< Rule2
<< "years.\n";}
else ( three )
Rule3 = 60 - Age;
Rule3.5 = 20 - Service;
{cout << "You can retire in "
<< Rule3
<< "years"
<< " or "
<< Rule35
<< "years.\n";}
system ("pause");
}
this is probably hell for your eyes.. i know i have a lot of useless things because i kinda gave up halfway. i'm just walking into blindness. i'm not sure how to approach this situation. would i use an if else statement for each rule?
double Age;
double Service;
double Rule1;
double Rule2;
double Rule3;
double Rule35;
double Rule4;
string one = Service <= 30;
string two = Age <= 65;
string three = Age <= 60 && Service <= 20;
string four = Age <= 55 && Service <= 25;
The double variables are not initialized. The expression, for example, string one = Service <= 30; as othe similar expressions has undefined behavior.
I give you a good advice before you will use anything in a program please read about it in books on programming!