Student Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sfsustudent
    New Member
    • Sep 2007
    • 2

    Student Question

    OK, so I read the information on students asking questions, so I just want to make this really clear. I am a student looking for help on a school assignment.

    So please help me format my question to an acceptable format for this forum if you feel I am inappropriate with it. Thank you.

    OK, so, I am just starting out, I am working on a very simple program to take user input of their name (first and last) in both upper and lower case characters, (all mixed up) and then output the name with only the first letter of the first and last name in upper case, and the rest in lower case.
    I have the program working to accept user input of their name, and display it back. (that was the easy part.) Now i am struggling with how to format the stored characters on cout.
    Any tips would be great, even if it is just the function I should be looking at. I have looked in my text book and online, but the only information I can find on upper to lower case conversion is only for single character conversion ( using toupper and tolower) I'm sure there is a simple way to use it on a string, but then how do you separate that out into the first character going up, and the rest going down.

    Sorry this wasn't a very well written question, and any criticism is probably well placed.

    Thanks in advance,

    sfsustudent
  • minkkp
    New Member
    • Sep 2007
    • 3

    #2
    Im kinda new at this but you would need use toupper();
    and inputone[0] and inputtwo[0] of what ever your cin was....
    [0], [1]. [2].........being the position of the character you want to be uppercase
    example:

    string firstname;
    cin >> firstname; //john

    fname [0] = toupper (firstname[0]);
    cout << firstname<<endl ;

    //john is the cin of string firstname
    //firstname[0] = j
    //firstname[1] = o
    //firstname[2]= h.............g et it?

    if you wanted to find the length of string firstname

    cout<<firstname .length()<<endl ;

    after compiling and running youd get 4?

    Comment

    • kreagan
      New Member
      • Aug 2007
      • 153

      #3
      You do need to use the functions toupper and tolower. (Atleast that is how would do it). And iterate through the whole string changing accordingly.

      what do you mean by "all mixed up"? Does this mean I can input "MichEAL Jackson" and you need to convert it to "Micheal Jackson"?

      PS. Your homework question was better written than most. Write the question verbatum and demand we write them code. lol.

      Comment

      • Laharl
        Recognized Expert Contributor
        • Sep 2007
        • 849

        #4
        The function strlwr(const char* s) takes a C-string and returns an entirely lower case representation of it, albeit in another C-string. C-strings, if you're unaware, are char[] with a special termination character at the end. Assuming you're using STL strings, a function exists in the std::string class that converts it to a C-string equivalent.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          I notice everyone is assuming this is a C class. If it's not, then your advice is suspect.

          Comment

          Working...