if else if statement the correct choice?

heey so for another project, i was wondering if i was going on the right track using the if else if statement.
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
/*

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>
using namespace 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";}
 else if ( 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?
Last edited on
What is it?!

1
2
3
4
5
6
7
8
9
10
11
  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!
Topic archived. No new replies allowed.