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
|
18 float calc_rect_area(float, float);
19
20 int main ()
21 {
22 float check, low, high;
23 float width, height;
24 string message;
25
26 get_float(message);
27 check_valid_input(check, low, high);
28 calc_rect_area(width, height);
29
30 const float MIN_VALUE = 1;
31 const float MAX_VALUE = 10;
32
33 float my_input = get_float("Enter a number from 1 to 10 ");
34 float sample_width = get_float("Enter the width for some imaginary rectangle");
35 float sample_height = get_float("Enter the height for some imaginary rectangle");
36
37 cout << my_input << endl;
38
39 cout << check_valid_input(my_input, MIN_VALUE, MAX_VALUE) << endl;
40
41 cout << calc_rect_area(sample_width, sample_height) << endl;
42
43 return 0;
44 }
45
46 float get_float(string message)
47 {
48 float check = atof(message.c_str());
49 return check;
50 }
51
52 float check_valid_input(float check, float low, float high)
53 {
54 float neg = -1.0;
55
56 if(check >= low && check <= high)
57 {
58 return check;
59 }
60 else
61 {
62 return neg;
63 }
64 }
65
66 float calc_rect_area(float width, float height)
67 {
68 if (height == 0)
69 return 0;
70 else
71 return width + calc_rect_area(width, --height);
72 }
|