-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced_vtora zadacha.cpp
85 lines (73 loc) · 1.9 KB
/
advanced_vtora zadacha.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
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int validateWeeksCount(string prompt)
{
int val;
while (true)
{
cin.clear();
cin.sync();
cout << prompt;
cin >> val;
if (cin.good() && val >= 1 && val <= 5)
{
break;
}
else
cin.clear();
cout << "Invalid input! Value must be between 2 and 31" << endl;
}
return val;
}
double validateTemperature(string prompt)
{
double val;
while (true)
{
cin.clear();
cin.sync();
cout << prompt;
cin >> val;
if (cin.good() && val >= -50 && val <= 50)
{
break;
}
else
cin.clear();
cout << "Invalid input! Temperature must be between -50 and 50 degrees" << endl;
}
return val;
}
bool equalTemp(double temp1, double temp2)
{
cout << fabs(temp1 - temp2) << endl;
return fabs(temp1 - temp2) <= 1;
}
int main()
{
int firstMonthWeeksCount = validateWeeksCount("Enter first month weeks count: ");
double firstMonth[firstMonthWeeksCount];
vector<int> result;
for(int i = 0; i < firstMonthWeeksCount; i++)
{
firstMonth[i] = validateTemperature("Enter temperature: ");
if (i == firstMonthWeeksCount - 1)
{
int secondMonthWeeksCount = validateWeeksCount("Enter second weeks count: ");
for(int j = 0; j < secondMonthWeeksCount; j++)
{
double secondMonthTemp = validateTemperature("Enter temperature: ");
if (equalTemp(firstMonth[j], secondMonthTemp)){
result.push_back(j + 1);
}
}
}
}
cout << "Weeks with nearly temperatures are: ";
for (vector<int >::const_iterator i = result.begin(); i != result.end(); ++i)
cout << *i << ' ';
cout << endl;
return 0;
}