Thread: testing and correcting lowercase

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    18

    testing and correcting lowercase

    hey guys im trying to test for lowercase and prompting user to enter uppercase this is what i have done but does not work any help would be appreciated thanks
    Code:
    	for(i=0;i<n;i++)
    	{
    		cout <<"\nPlease enter guess " << i+1 << " ";
    		cin >> guess[0];
    		while(islower(guess[0])==1)  // i also tried while(islower(guess[0]))
    		{
    			cout <<"\nPlease enter a Capital " <<endl;
    			cin >> guess[0];
    		}
    		guess++;
    	}
    Last edited by Rasher; 02-25-2010 at 02:48 AM.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    How does it not work? Does it not compile? What are the compilation errors? Does it not run? Does it do something unexpected? What did it do? What did you expect it to do?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    18
    sorry it compiles fine what i wanted it to do was if they entered a lowercase char into guess[0] to prompt them to enter a capital and loop until they entered a capital. At the moment it accepts both upper and lowercase with no crashing.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    18
    i have temp fixed it to work if there is a better way please let me know
    Code:
    for(i=0;i<n;i++)
    	{
    		cout <<"\nPlease enter guess " << i+1 << " ";
    		cin >> guess[0];
    		while(guess[0]>=91)
    		{
    			cout <<"\nPlease enter a Capital " <<endl;
    			cin >> guess[0];
    		}
    		guess++;
    	}

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    30
    I imagine that you would like to input a series of letters in capital into the array guess, yes? But in your code, whatever that's read in always goes to guess[0], instead of guess[i]. And you are always doing the testing on guess[0] too.

    That might be the problem.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Using islower() is better. It will work with other languages where lower and upper case make sense, too. Or even better, use !isupper. Right now you are trying to get user to enter anything that's NOT lower case (which includes numbers, symbols, etc).

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    18
    Quote Originally Posted by cyberfish View Post
    Using islower() is better. It will work with other languages where lower and upper case make sense, too. Or even better, use !isupper. Right now you are trying to get user to enter anything that's NOT lower case (which includes numbers, symbols, etc).
    i tried using islower and had no succcess maybe i did it wrong
    Code:
    (islower(guess))

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    (!isupper(guess[0]))

Popular pages Recent additions subscribe to a feed