Web Analytics Made Easy -
StatCounter tolower() help - CodingForum

Announcement

Collapse
No announcement yet.

tolower() help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • tolower() help

    For an assignment we need to be prompt the user to enter a department in the format of 3 letters then 3 numbers like itk168. We need to set it up to accept either caps or lower on the number part. How can I do it if I read in the department into a string. How do I go about converting the first 3 letters to lower and not mess with the numbers.


    string dept;
    cout << "Enter Department" << endl;
    getline(cin, dept);

    ?how do I use tolower() here?

    -GT

  • #2
    Did you try using it directly on the string. I'm not too familiar with tolower(), but my guess would be that it justs changes letters and doesn't mess around with numbers and symbols.

    shmoove

    Comment


    • #3
      can you not split the input like into two parts the numbers and the letters.

      scroots
      Spammers next time you spam me consider the implications:
      (1) that you will be persuaded by me(in a legitimate mannor)
      (2)It is worthless to you, when i have finished

      Comment


      • #4
        Instead of using getline() it would be easier to read the letters from user's character-input first, and then the integer afterwards:
        ---------------------------------

        string dept;
        cout << "Enter Department" << endl;
        // getline(cin, dept); getline() eats everything

        char ch = cin.peek(); // peek() returns the next char that may be read
        while(ch >= 65) { // while reading chars, 'A' == 65, 'B' == 66, etc
        // ch = char(tolower(ch)) // uncomment this conversion if needed
        dept += ch;
        ch = cin.peek();
        }

        string remainderOfInput;
        cin >> remainderOfInput; // get numbers
        dept += remainderOfInput;

        // cin.get() // kill '\n' if you want...

        --------------------------------------
        I think that's what you're trying to do.
        Last edited by Soy MrMike; Feb 26, 2004, 12:04 AM.

        Comment

        Working...
        X