charcter arrays???

hello every body

Example: if the entered characters are:s d A U M h t I
The output will be:
The letters are:t h d s

i wrote this code to do the example but it didnt work



# include<iostream>
#include <string>
# include<cctype>
using namespace std;

int main()
{
char arr[10];


for(int i=9;i>1;i--)

{
cin>>arr[i];



if(arr[i]<='a'&& arr[i]>='z')
{

cout<<arr[i];
}
else
cout<<"no small letters found";

}


return 0;


}
Your if statement is wrong. It shouldn't be possible for the if to evaluate to true. It is impossible for a single character to be <= 'a' AND >= Z. The loop should print "no small letters found" for every character.

Also, please use code tags and reformat posts in the future. If this example weren't so easy I wouldn't have even bothered to read it.

Use isLower in the <cctype> header. It already does what you need. Pass each value of the array to it and it returns true or false.
http://cplusplus.com/reference/clibrary/cctype/islower/
Last edited on
Your if condition will never be true.
Remember, if the arr[i] must be in the range 'a' <= arr[i] <= 'z', then code both those conditions using &&:
1
2
3
if (('a' <= arr[i]) && (arr[i] <= 'z'))
  {
  ...

kempofighter also posted you a link to a standard function which checks this very condtion:
1
2
3
if (islower( arr[i] ))
  {
  ...


Also, remember that you can only declare that there are "no small letters found" once you have finished checking every letter in the string.

Good luck!
Topic archived. No new replies allowed.