forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex5_21.cpp
More file actions
30 lines (26 loc) · 748 Bytes
/
ex5_21.cpp
File metadata and controls
30 lines (26 loc) · 748 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
// @Brief Revise the program from the exercise in 5.5.1(p. 191)
// so that it looks only for duplicated words that start with an uppercase letter.
// @See Exercise 5.20
// @frank67 Rewrite using the 'continue' statement. See #250
#include <iostream>
using std::cin; using std::cout; using std::endl;
#include <string>
using std::string;
int main()
{
string curr, prev;
bool no_twice = true;
while (cin >> curr)
{
if (isupper(curr[0]) && prev == curr)
{
cout << curr << ": occurs twice in succession." << endl;
no_twice = false;
break;
}
prev = curr;
}
if (no_twice)
cout << "no word was repeated." << endl;
return 0;
}