Jun 29, 2016 at 5:09am Jun 29, 2016 at 5:09am UTC
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
/*Program to count the number of lowercase characters entered*/
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int main()
{
char ch;
int count=0;
cout<<"Enter Character: " ;
cin.get(ch);
while (ch!='\n' )
{
if (islower(ch))
{
count++;
}
cin.get(ch); // Missing code
}
cout<<"\nThe number of lowercase characters are: " <<count<<"\n" ;
system("pause" );
return 0;
}
You forgot to tell the program to input (ch) before the next loop, and therefore (ch) remains unchanged. (ch) is not the newline character and unchanged, so (while) condition is always true and therefore the program loops forever.
Last edited on Jun 29, 2016 at 3:15pm Jun 29, 2016 at 3:15pm UTC
Jun 29, 2016 at 9:06am Jun 29, 2016 at 9:06am UTC
Thanks now it is working as it should.Yeah, one more question will it work with every input function like simple cin>>;or getchar()