-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimenumprinter.cpp
More file actions
72 lines (60 loc) · 2.18 KB
/
Primenumprinter.cpp
File metadata and controls
72 lines (60 loc) · 2.18 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
#include"Functions.cpp"
int main(){
typeEffect("=================================\n\033[32m Welcome to primenumberprinter\033[0m\n=================================\n", 50);
sleep_for(milliseconds(500));
bool x =true;
while(x==true){
typeEffect("\033[31mType the number you want to test: \033[33m", 50);
string SampleNumberStr;
cin >> SampleNumberStr;
cout << "\033[0m" << endl;
int total =50;
for (int i = 0; i <= total; ++i) {
showProgressBar(i, total);
std::this_thread::sleep_for(std::chrono::milliseconds(50)); // simulate work
}
cout << endl;
// Parse and validate numeric input from string
long long parsedValue = 0;
int SampleNumber;
try {
size_t idx = 0;
parsedValue = std::stoll(SampleNumberStr, &idx);
if (idx != SampleNumberStr.size() || parsedValue < INT_MIN || parsedValue > INT_MAX) {
cout << "Invalid input. Please enter an integer." << endl;
continue;
}
SampleNumber = static_cast<int>(parsedValue);
} catch (...) {
cout << "Invalid input. Please enter an integer." << endl;
continue;
}
if (isPrime(SampleNumber)) {
typeEffect(std::to_string(SampleNumber) + " is \033[32m a prime number.\033[0m\n", 50);
} else {
typeEffect(std::to_string(SampleNumber) + " is \033[31m not a prime number.\033[0m\n", 50);
}
cin.ignore();
cin.get();
string YN;
cout<<"Do you want to test another number?[\033[32my\033[0m/\033[31mn\033[0m] : \033[33m";
cin>>YN;
cout<<endl;
cout<<"\033[0m";
if(YN=="N"||YN=="n"||YN=="no"||YN=="NO"||YN=="No"||YN=="nO"){
bool x=false;
break;
}
else if (YN=="Y"||YN=="y"||YN=="yes"||YN=="YES")
{
bool x=true;
}
else{
cout<<"Invalid input, type yes or no"<<endl;
}
}
cin.ignore();
typeEffect("\033[31mThank you for using my program. Press enter to exit\033[0m", 50);
cin.get();
return 0;
}