Repository navigation
Expand file tree
/
Copy pathenter_print.cpp
More file actions
73 lines (61 loc) · 2.4 KB
/
Copy pathenter_print.cpp
File metadata and controls
73 lines (61 loc) · 2.4 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
#include <stdio.h>
#include <assert.h>
#include "solve_square_equation.h"
#include "enter_print.h"
#include "utils.h"
#include "color_scheme_changing.h"
int program_options_input() {
int choice = 0;
graphic_printf(BLACK, BOLD, "Выберите действие"
"\n\tРешение квадратного уравнения (введите 1)"
"\n\tЗапустить тест программы (введите 2)\n");
scanf("%1d", &choice);
return choice;
}
void enter_se_parameters(double *a, double *b, double *c) {
const int max_tries = 3;
assert(a);
assert(b);
assert(c);
graphic_printf(BLACK, BOLD, "Введите значения трех коэффициентов через пробел!\n");
for (int tryCounter = 0; tryCounter < max_tries; tryCounter++) {
int scanfResult = scanf("%lf %lf %lf", a, b, c);
if (!is_parameters_valid(*a, *b, *c)) {
graphic_printf(RED, BOLD, "Кошмар! Невозможные значения!!!\n");
}
if (scanfResult == 3) {
break;
}
else if (tryCounter == 2) {
graphic_printf(RED, BOLD, "ААААА!!! У Вас ОШИБКА!!!\n");
graphic_printf(BLACK, BOLD, "Конец программы!!! О нет!!! Тильт!!! Только не это!!!!!!!!!\n");
}
else {
graphic_printf(RED, BOLD, "Ошибка, введите снова. Да, я душнила.\n");
}
clear_buffer();
}
}
void print_solutions(const SE_SOLUTIONS *solutions) {
assert(solutions);
switch(solutions->num_of_sol) {
case ERROR_NUMBER:
graphic_printf(RED, BOLD, "Ошибка решения\n");
break;
case NO_SOLUTIONS:
graphic_printf(BLACK, BOLD, "Нет решений\n");
break;
case ONE_SOLUTION:
graphic_printf(BLACK, BOLD, "Одно решение: %lf\n", solutions->x1);
break;
case TWO_SOLUTIONS:
graphic_printf(BLACK, BOLD, "Два решения: %lf %lf\n", solutions->x1, solutions->x2);
break;
case INF_NUMBER_OF_SOLUTIONS:
graphic_printf(BLACK, BOLD, "Бесконечное количество решений\n");
break;
default:
graphic_printf(RED, BOLD, "Ошибка\n");
break;
}
}