-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.cpp
More file actions
51 lines (43 loc) · 1.34 KB
/
utils.cpp
File metadata and controls
51 lines (43 loc) · 1.34 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
#include "utils.h"
#include "login.h"
#include "exceptions.cpp"
#include <windows.h>
#include <iostream>
using namespace std;
int Utils::returnButton(int choice) {
while (true) {
try {
std::cout << "\033[31m[0]\033[0m Back" << std::endl;
std::cout << "Enter your choice: \033[32m";
std::cin >> choice;
cout << "\033[0m";
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(256, '\n');
throw std::invalid_argument("\033[31m[Not an integer. Try again.]\033[0m");
}
if (choice < 0 || choice > 9) {
throw std::out_of_range("\033[31m[Choice out of valid range. Try again.]\033[0m");
}
break;
} catch (const std::invalid_argument& e) {
std::cerr << "Invalid argument error: " << e.what() << std::endl;
delayAnimation(350);
} catch (const std::out_of_range& e) {
std::cerr << "Out of range error: " << e.what() << std::endl;
delayAnimation(350);
}
}
delayAnimation(350);
return choice;
}
void Utils::logout()
{
cout << "\033[32m[Redirecting to login page...]\033[32m" << endl;
delayAnimation(350);
}
void Utils::delayAnimation(double seconds)
{
Sleep(seconds);
system("cls");
}