469,336 Members | 5,695 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

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,

Sep 24 '07 #1
4 1165
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

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.............get it?

if you wanted to find the length of string firstname


after compiling and running youd get 4?
Sep 24 '07 #2
153 100+
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.
Sep 24 '07 #3
849 Expert 512MB
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.
Sep 24 '07 #4
9,208 Expert Mod 8TB
I notice everyone is assuming this is a C class. If it's not, then your advice is suspect.
Sep 25 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by Kirk Bevins | last post: by
8 posts views Thread by ChrisMac | last post: by
2 posts views Thread by sallyk07 | last post: by
11 posts views Thread by xxbabysue123xx | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.