-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.cpp
More file actions
138 lines (120 loc) · 3.6 KB
/
Copy pathCounter.cpp
File metadata and controls
138 lines (120 loc) · 3.6 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <Windows.h>
#include <string>
class Counter
{
private:
int value;
public:
Counter() : value(1) {}
Counter(int initValue) : value(initValue) {}
int increase() { return ++value; }
int decrease() { return --value; }
int getValue() const { return value; }
};
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
std::string userAnswer;
int userValue;
std::cout << "Вы хотите указать начальное значение счётчика? Введите да или нет: ";
std::cin >> userAnswer;
if (userAnswer == "да")
{
std::cout << "Введите начальное значение счётчика: ";
std::cin >> userValue;
Counter counter(userValue);
char comand;
while (true)
{
std::cout << "Введите команду ('+', '-', '=' или 'x'): ";
std::cin >> comand;
if (comand == '+')
{
counter.increase();
}
else if (comand == '-')
{
counter.decrease();
}
else if (comand == '=')
{
std::cout << counter.getValue() << std::endl;
}
else if (comand == 'x')
{
std::cout << "До свидания!" << std::endl;
break;
}
else
{
std::cout << "Неверная команда. Попробуйте снова." << std::endl;
}
}
}
else if (userAnswer == "нет")
{
Counter counter;
char comand;
while (true)
{
std::cout << "Введите команду ('+', '-', '=' или 'x'): ";
std::cin >> comand;
if (comand == '+')
{
counter.increase();
}
else if (comand == '-')
{
counter.decrease();
}
else if (comand == '=')
{
std::cout << counter.getValue() << std::endl;
}
else if (comand == 'x')
{
std::cout << "До свидания!" << std::endl;
break;
}
else
{
std::cout << "Неверная команда. Попробуйте снова." << std::endl;
}
}
}
else
{
std::cout << "Некорректный ввод. Используется значение по умолчанию (1)." << std::endl;
Counter counter;
char comand;
while (true)
{
std::cout << "Введите команду ('+', '-', '=' или 'x'): ";
std::cin >> comand;
if (comand == '+')
{
counter.increase();
}
else if (comand == '-')
{
counter.decrease();
}
else if (comand == '=')
{
std::cout << counter.getValue() << std::endl;
}
else if (comand == 'x')
{
std::cout << "До свидания!" << std::endl;
break;
}
else
{
std::cout << "Неверная команда. Попробуйте снова." << std::endl;
}
}
}
return 0;
}