-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest7.cpp
More file actions
76 lines (61 loc) · 2.04 KB
/
test7.cpp
File metadata and controls
76 lines (61 loc) · 2.04 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
// With Validation
#include <iostream>
#include <string>
#include <algorithm> // <== para sa reverse para dili nata mag for loops
using namespace std;
// gama gama rani nako ayaw mo pag expect kani mo gawas sa exam mga lods
int main() {
string str;
int num;
cout << "Try enter anyting e.g: Apple" << endl;
cout << "Enter string: ";
getline(cin, str);
cout << "Try any number to get single letter from 0 to " << str.length() - 1 << endl;
cout << "Enter number: ";
cin >> num;
if (num < 0) {
cout << "Invalid Number!" << endl;
return 1;
}
if (num > str.length() - 1) {
cout << "Number exceeds " << str.length() - 1 << endl;
cout << "try again pls input number from 0 to " << str.length() - 1 << endl;
return 1;
}
cout << "Num: " << num << " = " << str[num] << endl;
cout << "Total: " << str.length() - 1 << endl;
string balihon = str;
reverse(balihon.begin(), balihon.end());
cout << "Reverse String: " << balihon << endl;
cout << "Gusto ka magkuha og specifics string? example Apple pero ag resulta kay App" << endl;
cout << "(yes/no): ";
string choice;
int start, end;
cin >> choice;
if (choice == "yes" || choice == "YES" || choice == "y" || choice == "Y") {
cout << "e.g: 0" << endl;
cout << "Enter Begin: ";
cin >> start;
cout << "e.g: 2" << endl;
cout << "Enter End: ";
cin >> end;
} else {
cout << "Ok Dili so mao ra to : )";
return 1;
}
if (start > str.length() - 1) {
cout << "Ning Lapas imong start number!" << endl;
cout << "0 to " << str.length() -1;
return 1;
} else if (end > str.length() - 1) {
cout << "Ning Lapas imong end number!" << endl;
cout << "0 to " << str.length() -1;
return 1;
} else if (start < 0) {
cout << "Invalid!";
return 1;
}
string range = str.substr(start, end + 1);
cout << range;
return 0;
}