-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.cpp~
29 lines (25 loc) · 1.19 KB
/
11.cpp~
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
/*
The ASCII lowercase letters are separated from the uppercase letters by 32. Thus, to convert a lowercase letter to uppercase, subtract 32 from it. Use this information to write a program that reads characters from the keyboard. Have it convert all lowercase letters to uppercase, and all uppercase letters to lowercase, displaying the result. Make no changes to any other character. Have the program stop when the user enters a period. At the end, have the program display the number of case chagnes that have taken place.
*/
#include <iostream>
int main() {
char chr = ' ';
std::cout << "Enter your character: " << std::endl;
std::cin >> chr;
while (std::cin >> chr) {
if (chr == '.') {
break;
}
else if ((chr >= 65) && (chr <= 90)) {
std::cout << char(chr + 32) << std::endl;
}
else if ((chr >= 97) && (chr <= 122)) {
std::cout << char(chr - 32) << std::endl;
}
else
std::cout << chr << std::endl;
}
std::cout << "You have entered a period (.).\n"
<< "The program ends here." << std::endl;
return 0;
}