-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced_purva_zadacha.cpp
76 lines (66 loc) · 1.5 KB
/
advanced_purva_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
#include <iostream>
using namespace std;
int validateDaysCount(string prompt)
{
int val;
while (true)
{
cin.clear();
cin.sync();
cout << prompt;
cin >> val;
if (cin.good() && val >= 2 && val <= 31)
{
break;
}
else
cin.clear();
cout << "Invalid input! Value must be between 2 and 31" << endl;
}
return val;
}
int validateTemperature(string prompt)
{
int 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;
}
int main()
{
int numberOfDays = validateDaysCount("Enter a number between 2 and 31: ");
int daysArray[numberOfDays];
int previousDayTemp = 0;
int higherTempCounter = 0;
for(int i = 0; i < numberOfDays; i++)
{
daysArray[i] = validateTemperature("Enter temperature: ");
if (i == 0)
{
previousDayTemp = daysArray[0];
}
else
{
if (daysArray[i] > previousDayTemp)
{
higherTempCounter++;
}
previousDayTemp = daysArray[i];
}
}
cout << "Number of days with higher temperature is: " << higherTempCounter << endl;
cout << endl;
return 0;
}