Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
C++
#include <cstdlib>
#include <iostream>
#include<conio.h>
#include<string.h>
using namespace std;

int main()
{
    int upper=0;
    string s;
    int i;
    
     
    
cout<<"Enter a String";
cin>>s;
   
    for(i=0;i<=s.size();i++)
    {
        if(s[i]>='A'&& s[i]<='Z')
        {
        upper++;
    }
        
    }
  int len=s.length();
    cout<<" The Number of Upper case Letter is"<<upper;
    cout<<"length"<<len;
    getch();
    return 0;
    
}
Posted

1 solution

Using cin >> s; will terminate at whitespace, try reading a full line using getline instead;
Replace
C++
cout<<"Enter a String";
cin>>s;

with
C++
cout<<"Enter a String";
getline(cin, s);

Hope this helps,
Fredrik
 
Share this answer
 
Comments
Member 10578683 8-Jan-15 3:56am    
Thanks
Fredrik Bornander 8-Jan-15 7:51am    
Glad I could help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900