I am working on a programming exercise, "Count of camel case characters" using C++. The goal of the exercise is to count the number of upper-case letters in a given string (what the exercise calls "camel case").
So given the following two inputs:
- ckjkUUYII
- HKJT
I would expect to get the following counts respectively:
- 5
- 4
Based on the code I've include below, however, I am instead getting:
- 0
- 5
This is clearly incorrect, but I've having difficulty isolating the problem in my code. How can I reason through this problem, or debug my error?
#include <iostream>
#include <cstring>
using namespace std;
int main() {
    int t;cin>>t;
    while(t--)
    {
        int res=0;
        string str;
        getline(cin,str);
        int len= str.length();
        for(int i=0;i<len;i++)
        {
            int c=str[i];
            if(isupper(c))
            res=res+1;
        }
        cout<<res<<endl;
    }
    //return 0;
}
 
     
     
    