-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.17.cpp
More file actions
50 lines (45 loc) · 952 Bytes
/
6.17.cpp
File metadata and controls
50 lines (45 loc) · 952 Bytes
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
#include <iostream>
#include <string>
#include <cctype>
#include <stdexcept>
using std::runtime_error;
using std::cin;
using std::string;
using std::cout;
using std::endl;
bool hasCapital(const string &s) {
for (const char &c : s) {
if (isupper(c))
return true;
}
return false;
}
void toLowercase(string &s) {
for (char &c : s){
c = tolower(c);
}
}
int main() {
bool torepeat;
do {
try {
torepeat = false;
string word;
if (!(cin >> word))
throw runtime_error("Invalid input!");
if (hasCapital(word)) {
cout << "String contains at least one capital letter." << endl;
toLowercase(word);
cout << "Lowercase string: " << word << endl;
} else {
cout << "String doesn't have any capital letters." << endl;
}
} catch (runtime_error e) {
cout << e.what() << "\nTry again? (y/n): ";
char choice;
if (cin >> choice && choice == 'y')
torepeat = true;
}
} while (torepeat);
return 0;
}