I liked this, currently learning C++ myself and I'm in chapter 3 of C++ Primer (On arrays, not fun) but I wanted to give this a try because it uses a function from the chapter. So I came up with this.
Code
char c;
void main()
{
cout << "Please type a letter, and I will tell you if it is a capital or a lower-case letter: ";
while (cin >> c)
{
if (isupper(c))
{
cout << c << " is capital letter." << endl;
}
else
{
cout << c << " is a lowercase letter." << endl;
}
}
}
Same concept but on a string
Code
string input;
int cap_count, low_count;
void main()
{
cout << "Type a sentence and I will tell you how many capital letters and lowercase are in it: " << endl;
while (getline(cin, input))
{
for (auto c : input)
{
if (isupper(c))
{
++cap_count;
}
else if (islower(c) && !isspace(c))
{
++low_count;
}
}
cout << cap_count << " capital letters and " << low_count << " lowercase letters." << endl;
cap_count -= cap_count;
low_count -= low_count;
}
}
This post was edited by InunoTaishou on Aug 2 2014 08:02pm