-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTask 2.cpp
106 lines (92 loc) · 2.87 KB
/
Task 2.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
using namespace std;
int main()
{
int SIZE = 13;
int *ptrFirmsProfitMonth = new int[SIZE];
cout << "\tEnter salary." << endl; cout << endl;
for (int i = 1; i < SIZE; i++)
{
switch (i)
{
case 1:
cout << "Enter salary for 1 - January in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 2:
cout << "Enter salary for 2 - February in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 3:
cout << "Enter salary for 3 - March in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 4:
cout << "Enter salary for 4 - April in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 5:
cout << "Enter salary for 5 - May in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 6:
cout << "Enter salary for 6 - June in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 7:
cout << "Enter salary for 7 - July in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 8:
cout << "Enter salary for 8 - August in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 9:
cout << "Enter salary for 9 - September in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 10:
cout << "Enter salary for 10 - October in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 11:
cout << "Enter salary for 11 - November in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
case 12:
cout << "Enter salary for 12 - December in USD: "; cin >> ptrFirmsProfitMonth[i];
break;
}
}
cout << endl;
int minRange;
int maxRange;
do
{
cout << "\tEnter the salary search range from 1 to 12 month: " << endl; cout << endl;
cout << "Min range: "; cin >> minRange;
cout << "Max range: "; cin >> maxRange;
if (13 > minRange > 0 && 13 > maxRange > 0)
{
break;
}
else
{
cout << "You have entered an invalid value! Please re-enter!";
}
} while (true);
int min = ptrFirmsProfitMonth[minRange];
int max = ptrFirmsProfitMonth[minRange];
int minMonth = minRange;
int maxMonth = minRange;
for (int i = minRange; i < maxRange; i++)
{
if (min > ptrFirmsProfitMonth[i]) // определение минимального элемента
{
min = ptrFirmsProfitMonth[i];
minMonth = i;
}
if (max < ptrFirmsProfitMonth[i]) // определение максимального элемента
{
max = ptrFirmsProfitMonth[i];
maxMonth = i;
}
}
cout << endl;
cout << "\tMinimum and maximum salary in a given period from " << minRange << " to " << maxRange << " months." << endl; cout << endl;
cout << "The minimum salary for month number " << minMonth << " is equal to: " << min << "$"; cout << endl; cout << endl;
cout << "The maximum salary for month number " << maxMonth << " is equal to: " << max << "$";
delete[] ptrFirmsProfitMonth;
cout << endl; cout << endl;
system("pause");
return 0;
}