Thread: Max Of Ascii

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    71

    Smile Max Of Ascii

    hi everyone, here is one code that i stuck with

    the aim of this program is to find the largest ascii code that was converted by the given lowercase name.

    Code:
        for(int i = 0; name[i]; i++)
        {
        	lowerCase = static_cast<char>(tolower(name[i]));//convert to lowercase
        	
       		for(int j = 0; lowerCase[j]; j++)
        	{
         		int lower =  lowerCase[0];//find lowercase ASCII
         		
         		cout<<lower<<" ";
        	} 
            
       	}
    can someone please

    i am thkning to use max_value but still couldnt make it.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    1. there is no need to typecase tolower().
    2. why the inner loop? just use another int object to keep track of the lowest value while the outer loop is running, which will make your program run a whole lot faster. For example
    Code:
    int max_value = -1;
       for(int i = 0; name[i]; i++)
        {
        	int lowerCase = tolower(name[i]);//convert to lowercase
            if( lowerCase > max_value)
                 max_value = lowerCase;
        }
        cout << "max = " << max_value << endl;

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    hi Ancient Dragon,
    can you tell me what is this code do?
    Code:
    int max_value = -1;
    thank you.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    It assigns -1 to the integer variable max_value. There are no ascii codes lower than -1.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    actully there are no ascii codes lower than 0. EOF (-1) is not an ascii code. ascii codes are in the range 0-127.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    ok thanks a lot, i really appreciate the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find max profit among input salary
    By hlam in forum C Programming
    Replies: 8
    Last Post: 11-16-2008, 10:30 AM
  2. Max Min Problem
    By smithc2005 in forum C Programming
    Replies: 7
    Last Post: 10-22-2008, 10:38 AM
  3. Ranged numbers
    By Desolation in forum Game Programming
    Replies: 8
    Last Post: 07-25-2006, 10:02 PM
  4. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  5. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM